We help IT Professionals succeed at work.
Get Started

Changing a value in an encrypted file using VBA

480 Views
Last Modified: 2012-05-11
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
This problem has been solved!
Unlock 1 Answer and 7 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE