Hello,
I want to decrypt a string I have encrypted before in b4a and send it to a VB6-application via TCI/IP.
This is my code:
Does anyone know of a working function/solution for VB6 to decode the text?
I have allready tried in vain the "mdAesCtr.bas" module (over hours) from this side:
But it seams then InitialisationVector in this module this is not taken into account.
Thank you!
I want to decrypt a string I have encrypted before in b4a and send it to a VB6-application via TCI/IP.
This is my code:
ecnrypt a string:
Sub AES_encrypt(was As String) As String
Dim PW = "myPW1234561234567890123456789012" As String
Dim salt = "1234567890123456" As String
Dim IV = "IV98765432109876" As String
Return my_encrypt( was.GetBytes("UTF8"), PW.GetBytes("UTF8"), salt.GetBytes("UTF8"), IV.GetBytes("UTF8"), True)
End Sub
Sub my_encrypt(data() As Byte, passB() As Byte, SaltB() As Byte, IVb() As Byte, ReturnB64String As Boolean) As Object
Dim su As StringUtils
Dim kg As KeyGenerator
Dim C As Cipher
kg.Initialize("AES")
kg.KeyFromBytes(passB)
C.Initialize("AES/CBC/PKCS5Padding")
C.InitialisationVector = IVb
Dim datas() As Byte = C.Encrypt(data, kg.Key, True)
Dim SaltIVMessage(SaltB.Length + datas.Length) As Byte = AddSaltIVMessage(SaltB,IVb, datas)
Log("Länge=" & (SaltB.Length + datas.Length + IVb.Length))
If ReturnB64String Then
Return su.EncodeBase64(SaltIVMessage)
Else
Return SaltIVMessage
End If
End Sub
Private Sub AddSaltIVMessage (Salt() As Byte,IV() As Byte, Message () As Byte) As Byte()
Dim bc As ByteConverter
Dim SaltIVMessageBytes (Salt.Length + IV.Length + Message.Length) As Byte
bc.ArrayCopy(Salt,0,SaltIVMessageBytes,0,32)
bc.ArrayCopy(IV,0,SaltIVMessageBytes,32,16)
bc.ArrayCopy(Message,0,SaltIVMessageBytes,48,Message.Length)
Return SaltIVMessageBytes
End Sub
Does anyone know of a working function/solution for VB6 to decode the text?
I have allready tried in vain the "mdAesCtr.bas" module (over hours) from this side:
[VB6/VBA] Simple AES 256-bit password protected encryption-VBForums
Simple AES 256-bit password protected encryption A single mdAesCtr.bas module contains an implementation of a simple to use openssl compatible AES 256-bit encryption/decryption in Counter (CTR) mode, using CNG API functions available in Win7 and later. Sample usage Just copy/paste...
www.vbforums.com
But it seams then InitialisationVector in this module this is not taken into account.
Thank you!