Click here to Skip to main content
15,883,901 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have used VB6 one module for encryption / decryption and compare the encrypted string
with another string which always say Not Matched.

Below is the code

What I have tried:

VB
Dim a As String
a = modEncDec.AesEncryptString("a", "PASS") ' Encrypted Value of a is tA==
If a = "tA==" Then
MsgBox "The Value of a is " & a, vbOKOnly, "Matched"
Else
MsgBox "The Value of a is " & a, vbOKOnly, "Not Matched"
End If


Else Part is executed even though the Strings were same.
Posted
Updated 5-Aug-22 7:54am
Comments
Richard MacCutchan 5-Aug-22 5:47am    
It is quite possible that the encrypted text contains some non-displayable characters. Try writing it to a file and see how many actual bytes you get. Have you actually tried to decrypt it to check that the original text is returned?

Having said that, you do realise that VB6 has been dead for more than 20 years.

The chances are that the problem lies in the use of strings: AES encryption does not generate a string but a stream of byte values which is not the same thing.
VB6 internally used Unicode for string storage, which is a multibyte character, so it's very, very possible that the conversion to a string is what's causing the problem - the characters you see are not what the "string" returned by the encryption process produces.

Try using an array of bytes instead and see exactly what you get.
 
Share this answer
 
Comments
Member 11291660 5-Aug-22 13:47pm    
Thank you Mr. OriginalGriff.
After Converting it as byte array, I encountered two more characters were added at the end. Chr(10) and Chr(13) [vbCrLf].

Removing these two character did the job. Thank you
OriginalGriff 5-Aug-22 13:49pm    
You're welcome!
It looks like you are encrypting the string "a", decrypting it and then comparing it to the string "tA==".

Try comparing to the string "a" instead and see if that works.
 
Share this answer
 
Comments
Richard MacCutchan 5-Aug-22 12:00pm    
No s/he is comparing the encrypted string; there is no decryption.
Member 11291660 5-Aug-22 13:52pm    
Mr.Fueled By Decaff, You are Right. Both are different in length.
My 5 Stars
VB
Dim a As String
Dim b As String
a = modEncDec.AesEncryptString("a", "PASS")
b = "tA=="
a = Replace(a, vbCrLf, "")
If a = b Then
MsgBox "The Value of a is " & a & vbCrLf _
        & "The Length of a is " & Len(a) & vbCrLf _
        & "The Value of b is " & b & vbCrLf _
        & "The Length of b is " & Len(b) & vbCrLf, _
         vbOKOnly, "Matched"
Else
MsgBox "The Value of a is " & a & vbCrLf & "The Length of a is " & Len(a) & vbCrLf _
        & "The Value of b is " & b & vbCrLf _
        & "The Length of b is " & Len(b) & vbCrLf, _
        vbOKOnly, "Not Matched"
End If
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900