Re: Unable to decrypt (General questions)
Chris,
ok, I got it. OpenSSL's enc command creates IV and KEY based on params you enter, but doesn't use exactly that key to encrypt data. I've been able to duplicate it. For example, if you encrypt data using this command line:[code]openssl enc -aes256 -in test.txt -out test.out -nosalt -pass pass:12345678901234561234567890123456[/code]you can use following VB code to decrypt it. First, here's function that is same as OpenSSL's ENC command, to convert key to his internal KEY/IV [code]Private Sub CreateKeyIV(key As MemBlob, keylen, iv As MemBlob, ivlen)
Dim c As wodCryptCom
Dim addoldmd5 As Boolean
Dim hexkey As String
Dim oldmd5 As String
addoldmd5 = False
hexkey = key.ToHex
key.FromHex
iv.FromHex
Dim needmore As Boolean
needmore = True
Do
Set c = New wodCryptCom
c.Type = MD5
Dim inblob1 As New MemBlob
Dim outblob1 As New MemBlob
Dim keydata As String
If addoldmd5 Then keydata = oldmd5
keydata = keydata & hexkey
inblob1.FromHex keydata
c.Digest inblob1, outblob1
addoldmd5 = True
oldmd5 = outblob1.ToHex
' where to we save this?
Dim old As String
If Len(key.ToHex) / 2 < keylen Then
old = key.ToHex
old = old & oldmd5
key.FromHex old
Else
If Len(iv.ToHex) / 2 < ivlen Then
old = iv.ToHex
old = old & oldmd5
iv.FromHex old
Else
needmore = False
End If
End If
Loop While needmore
End Sub[/code], and finally, here's my code that will read 'test.out' and will put it's decrypted contents to screen [code] Dim iv As New MemBlob
Dim key As New MemBlob
Dim Crypt1 As wodCryptCom
Set Crypt1 = New wodCryptCom
Crypt1.Type = AES256
Crypt1.Mode = CBC
Crypt1.Optimized = False
Crypt1.Padding = PadPKCS7
key.Text = 12345678901234561234567890123456
CreateKeyIV key, Crypt1.KeySize, iv, Crypt1.BlockSize
Crypt1.SecretKey = key
Crypt1.InitVector = iv
Dim indata As New MemBlob
indata.FromFile test.out
Dim outdata As New MemBlob
Crypt1.Decrypt indata, outdata
MsgBox outdata.Text
[/code] Please try this out. We'll try to make VB sample in next few days and put it into regular distribution.
Hope this all helps!
Kreso
Complete thread:
- Unable to decrypt - Chris, 2007-05-10, 22:39
- Re: Unable to decrypt - wodSupport, 2007-05-10, 23:21
- Re: Unable to decrypt - Chris, 2007-05-11, 16:34
- Re: Unable to decrypt - woddrazen, 2007-05-11, 18:33
- Re: Unable to decrypt - wodSupport, 2007-05-12, 00:46
- Re: Unable to decrypt - wodSupport, 2007-05-12, 16:08
- Re: Unable to decrypt - Chris, 2007-05-31, 16:51
- Re: Unable to decrypt - woddrazen, 2007-05-31, 20:04
- Re: Unable to decrypt - Chris, 2007-05-31, 16:51
- Re: Unable to decrypt - wodSupport, 2007-05-12, 16:08
- Re: Unable to decrypt - wodSupport, 2007-05-12, 00:46
- Re: Unable to decrypt - woddrazen, 2007-05-11, 18:33
- Re: Unable to decrypt - Chris, 2007-05-11, 16:34
- Re: Unable to decrypt - wodSupport, 2007-05-10, 23:21