Re: Unable to decrypt (General questions)
Sorry for the delay, I was pulled by production issues.
Anyway, I am trying to get this working in our VBScript application and am having problems with the digest line.
I am getting the error:
Type mismatch: 'objWodCryptCom.Digest'
code: 800A000D
Source: Microsoft VBScript runtime error
System: The data is invalid
I'm not sure what I have done wrong in my conversion from your vb code to vbscript. Any help would be appreciated.
Thanks,
Chris
Here is my converted code:
Sub CreateKeyIV(objKey, intKeyLen, objIV, intIVLen)
Dim objWodCryptCom
Dim boolAddOldMD5
Dim strHexKey
Dim strOldMD5
Dim boolNeedMore
Dim objInBlob1
Dim objOutBlob1
Dim strKeyData
Dim strOld
boolAddOldMD5 = False
strHexKey = objKey.ToHex
objKey.FromHex
objIV.FromHex
boolNeedMore = True
Do
Set objWodCryptCom = CreateObject( WeOnlyDo.wodCrypt.1 )
objWodCryptCom.Type = 100 'MD5
Set objInBlob1 = CreateObject( WeOnlyDo.MemBlob.1 )
Set objOutBlob1 = CreateObject( WeOnlyDo.MemBlob.1 )
If boolAddOldMD5 Then strKeyData =strOldMD55
strKeyData = strKeyData & strHexKey
objInBlob1.FromHex strKeyData
objWodCryptCom.Digest objInBlob1, objOutBlob1
boolAddOldMD5 = True
strOldMD5 = objOutBlob1.ToHex
If Len(key.ToHex) / 2 < intKeyLen Then
strOld = key.ToHex
strOld = strOld & strOldMD5
objKey.FromHex strOld
Else
If Len(iv.ToHex) / 2 < intIVLen Then
strOld = iv.ToHex
strOld = strOld & strOldMD5
objIV.FromHex strOld
Else
boolNeedMore = False
End If
End If
Loop While boolNeedMore
End Sub
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
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