Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Encrypting and savinc in registry

Status
Not open for further replies.

rohini21

Programmer
Jan 19, 2003
49
0
0
NZ
Hello Everyone,

I would appreciate if someone could help me what I am trying to achieve. I want to build a small application for my company which encrypts the connection string and saves it into registry. Later on I would like to fetch the encrypted connection string decrypt and use it for the connection.

I found a nice article on MSDN but that is specific to .NET and I am looking for VB 6.0 and ASP. Please note no .NET at all.

Thanks
 
How encrypted do you want the connection string to be?
 
Here's a couple of simple encryption/decryption functions if you don't need anything fancy.
Code:
Function fDecrypt(ByVal strKey As String, ByVal strInput As String) As String
    
    '--- Decrypts a string encrypted by fEncrypt

    '--- Parameters
    'strKey: the private key used to encrypt the string
    'strInput: the encrypted string to decrypt

    Dim intC1 As Integer
    Dim lngKey As Long
    Dim aintRVal() As Integer
    Dim intTemp As Integer
    
    If strKey = vbNullString Or _
    strInput = vbNullString Then Exit Function
    
    'Generate the encryption key value from strKey
    For intC1 = 1 To Len(strKey)
        lngKey = lngKey + Asc(Mid$(strKey, intC1, 1))
    Next
    
    'Seed the randomizer
    Rnd (-1)
    Randomize lngKey
    
    'Generate a series of random numbers between
    '32 and 159 for the chars in strInput
    ReDim aintRVal(1 To Len(strInput))
    For intC1 = 1 To Len(strInput)
        aintRVal(intC1) = ((Rnd() * 127) + 1) Mod 223 + 32
    Next
    
    'Decrypt strInput
    For intC1 = 1 To Len(strInput)
        intTemp = ((Asc(Mid$(strInput, intC1, 1)) - aintRVal(intC1)) Mod 223) - 32
        If intTemp < 0 Then intTemp = intTemp + 223
        fDecrypt = fDecrypt & Chr$(intTemp)
    Next
    
End Function
'___________________________

Public Function fEncrypt(ByVal strKey As String, ByVal strInput As String) As String
    
    '--- Encrypts a string

    '--- Parameters
    'strKey: the private key used to encrypt the string
    'strInput: the string to encrypt

    Dim intC1 As Integer
    Dim lngKey As Long
    Dim aintRVal() As Integer
    
    If strKey = vbNullString Or _
    strInput = vbNullString Then Exit Function
    
    'Generate the encryption key value from strKey
    For intC1 = 1 To Len(strKey)
        lngKey = lngKey + Asc(Mid$(strKey, intC1, 1))
    Next
    
    'Seed the randomizer
    Rnd (-1)
    Randomize lngKey
    
    'Generate a series of random numbers between
    '32 and 159 for the chars in strInput
    ReDim aintRVal(1 To Len(strInput))
    For intC1 = 1 To Len(strInput)
        aintRVal(intC1) = ((Rnd() * 127) + 1) Mod 223 + 32
    Next
    
    'Encrypt strInput
    For intC1 = 1 To Len(strInput)
        fEncrypt = fEncrypt & _
        Chr$(((Asc(Mid$(strInput, intC1, 1)) + aintRVal(intC1)) Mod 223) + 32)
    Next
    
End Function
There are numerous examples of using the registry API functions if you search this forum or Google.

Paul Bent
Northwind IT Systems
 
How encrypted? I think I want the string to be secure enough so that no one can hack :) ... I know its microsoft but ... Well my intention is really making the application secure. Honestly, I do not know how much encryted can one make it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top