Link to home
Start Free TrialLog in
Avatar of Tracy
TracyFlag for United States of America

asked on

Changing a value in an encrypted file using VBA

I'm trying to replace a value in an encrypted file.  We changed servers, so the new server name needs to be added to the encrypted ini file.

This temporary fix works, but it defeats the purpose of the encrypted file if you enter the data directly into the code:
Public Property Get Server() As String
    'Work around
    'Server = "PEFSSQL01" ''Hard coded server name change. Change made on 5-11-11
   
   'Original code
   Server = DecryptString(msSvrNm, msCrypKey, True)
End Property

This code works (decryptStringCode), it produces the correct result with the hex encryption value given.  The correct result is PEFSSQL01.  However, when I copy this hex string into the ini file and then run the checkServerName procedure, it does not produce the correct result.

So what I need is to replace the hex string between the <s> </s> tags in the ini file and have the result of the checkServerName equaled to PEFSSQL01.

I've stripped out some of the values in the encrypted file.  Attached is the workbook with the class module and regular module where I'm testing.  The ini file should be saved in a folder called 'cfg'.  The 'cfg' folder should be in the same directory where you save the workbook.

Thanks in advance for the help, I've been trying for a day now to figure this out.

Tracy
Sub decryptStringCode()
   
   Dim clsX As cls_Cfg
    
    Set clsX = New cls_Cfg

    '****************************************
    'This produces the result: PEFSSQL01
    Debug.Print clsX.DecryptString("EB29DEABBF877B585F6FBB29F987B913545771F67D68C092", "L0c@lKeyKrypt", True)
    '****************************************

    Set clsX = Nothing
 
End Sub

Open in new window

Sub checkServerName()

    Dim clsX As cls_Cfg
    
    Set clsX = New cls_Cfg

    MsgBox "Server Name: " & clsX.Server 'Does not show correct result of PEFSSQL01
    MsgBox "User Name: " & clsX.User 'Shows correct result

    Set clsX = Nothing

End Sub

Open in new window

pemirr.ini
Book1.xlsm
Avatar of Arno Koster
Arno Koster
Flag of Netherlands image

That will be because of the encruption key having the value
date-06232010!@#$@#$FAS

Open in new window

instead of
L0c@lKeyKrypt

Open in new window

at the time of executing the Get Server() property of cls_Cfg.
Avatar of Tracy

ASKER

Yes, I've tried it with both keys.  The decryptStringCode results in PEFSSQL01 with either one I use.  However, the checkServerName procedure doesn't produce the correct result for either key.
ASKER CERTIFIED SOLUTION
Avatar of Arno Koster
Arno Koster
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Tracy

ASKER

Interesting, that works for me too.  I think I know what happened.  I used the encryptString module to encrypt PEFSSQL01, that's how I got the hex string.  I must've used the "L0c@lKeyKrypt" key when doing it, and the other fields used the "date-06232010!@#$@#$FAS" key.

So now I need to produce the hex string using the "date-06232010!@#$@#$FAS" instead.  Any chance you can do that and post the hex you get so I can compare with what I get?  Cause I did it before and every time I run it, it produces a different result (ie. the hex is not the same, but the outcome is).

Thanks a lot.  If you don't have time, I'll accept http:35778278 as the solution.
Avatar of Tracy

ASKER

This is what I got using the "date-06232010!@#$@#$FAS" key:

"0C412F2AF06FCFC9B6903982F6445DCD84F5D4D7B0E4A0DE"
Avatar of Tracy

ASKER

Thanks a lot!
you're welcome !