Changing a value in an encrypted file using VBA

Tracy
Tracy used Ask the Experts™
on
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
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
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.
TracyVBA Developer

Author

Commented:
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.
Strange, using these procedures I get the correct results.

Public Property Get Server() As String
    'Server = "PEFSSQL01" ''Hard coded server name change. Change made on 5-11-11
    msCrypKey = "L0c@lKeyKrypt"
    Server = DecryptString(msSvrNm, msCrypKey, True)
End Property

Public Property Get User() As String
  msCrypKey = "date-06232010!@#$@#$FAS"
  User = DecryptString(msUsrNm, msCrypKey, True)
End Property

Open in new window

Success in ‘20 With a Profitable Pricing Strategy

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

TracyVBA Developer

Author

Commented:
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.
TracyVBA Developer

Author

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

"0C412F2AF06FCFC9B6903982F6445DCD84F5D4D7B0E4A0DE"
TracyVBA Developer

Author

Commented:
Thanks a lot!
you're welcome !

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial