Unable to decrypt - WeOnlyDo Discussion board

Unable to decrypt (General questions)

by Chris, Thursday, May 10, 2007, 22:39 (6407 days ago)

I am trying to test your product for our company. However, I am having problems decrypting files.

If I encrypt a file with wodCrypt, I can decrypt it with wodCrypt.

However, if I use openssl to encrypt a file on my linux box, wodCrypt will not decrypt it. I keep getting:

Failed to decrypt data. Try setting optimized=FALSE

setting optimized to false does not decrypt the file, the decrypted file is not readable.

Here is my encryption command:
openssl enc -aes256 -in test.file -out test.enc -salt -pass file:<path to password file>

Please let me know what is wrong, why wodCrypt can not decrypt openssl encrypted files.

Thanks,

Chris

Re: Unable to decrypt

by wodSupport, Thursday, May 10, 2007, 23:21 (6407 days ago) @ Chris

Chris,

hi. I am not 100 sure, but I don't think you will find any other tool that will be able to decrypt OpenSSL's encrypted files the way you encrypt them now. Not sure why, but command line OpenSSL tool isn't straightforward encryption, it has other things involved too (for example, what would 'salt' be for?)

If you have any other tool that decrypts it, I will be happy to see how to duplicate that behavior with wodCrypt.

Kreso

Re: Unable to decrypt

by Chris, Friday, May 11, 2007, 16:34 (6406 days ago) @ wodSupport

Can you recommend a working encryption program to use on the Linux side? We are needing to encrypt and transfer files between windows and linux over the internet and need to use AES256 encryption. If openssl does not work with with your activex control, what does?

thanks for any assistance,

Chris

Chris,

hi. I am not 100 sure, but I don't think you will find any other tool that will be able to decrypt OpenSSL's encrypted files the way you encrypt them now. Not sure why, but command line OpenSSL tool isn't straightforward encryption, it has other things involved too (for example, what would 'salt' be for?)

If you have any other tool that decrypts it, I will be happy to see how to duplicate that behavior with wodCrypt.

Kreso

Re: Unable to decrypt

by woddrazen, Friday, May 11, 2007, 18:33 (6406 days ago) @ Chris

Hi Chris,


Kreso told me that he will examine over a weekend what OpenSSL do while encrypting files. If he find out something he will try to make wodCrypt to be compatible with OpenSSL.

In that case you will be able to decrypt OpenSSL encrypted files with wodCrypt.


Regards,
Drazen

Re: Unable to decrypt

by wodSupport, Saturday, May 12, 2007, 00:46 (6406 days ago) @ woddrazen

Chris,

BTW if you wish you could also check this post:

http://www.weonlydo.com/index.asp?forum=1&action=view&topic=1087424090#1087424090

Kreso

Re: Unable to decrypt

by wodSupport, Saturday, May 12, 2007, 16:08 (6405 days ago) @ wodSupport

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

Re: Unable to decrypt

by Chris, Thursday, May 31, 2007, 16:51 (6386 days ago) @ wodSupport

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

Re: Unable to decrypt

by woddrazen, Thursday, May 31, 2007, 20:04 (6386 days ago) @ Chris

Hi Chris,


Please try something like this (it worked for me):

[code]
Dim iv, key
Set key = CreateObject( WeOnlyDo.MemBlob.1 )
Set iv = CreateObject( WeOnlyDo.MemBlob.1 )

Sub CreateKeyIV(key, keylen, iv, ivlen)
Dim c,addoldmd5, needmore, inblob1, outblob1, keydata, old
Set c = WScript.CreateObject( WeOnlyDo.wodCryptCom.1 ) '...Com is missing in you sample
Set inblob1 = CreateObject( WeOnlyDo.MemBlob.1 )
Set outblob1 = CreateObject( WeOnlyDo.MemBlob.1 )

addoldmd5 = False
hexkey = key.ToHex

key.FromHex
iv.FromHex

needmore = True

Do

c.Type = 100

If addoldmd5 Then keydata = oldmd5
keydata = keydata & hexkey
inblob1.FromHex(keydata)
c.Digest inblob1, outblob1

addoldmd5 = True
oldmd5 = outblob1.ToHex

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


Dim Crypt1, indata, outdata

Set Crypt1 = WScript.CreateObject( WeOnlyDo.wodCryptCom.1 ) '...Com is missing in you sample
Set indata = CreateObject( WeOnlyDo.MemBlob.1 )
Set outdata = CreateObject( WeOnlyDo.MemBlob.1 )

Crypt1.Type = 4
Crypt1.Mode = 1
Crypt1.Optimized = False
Crypt1.Padding = 3

key.Text = 12345678901234561234567890123456
CreateKeyIV key, Crypt1.KeySize, iv, Crypt1.BlockSize
Crypt1.SecretKey = key
Crypt1.InitVector = iv

indata.FromFile c: est.out

Crypt1.Decrypt indata, outdata

Wscript.Echo outdata.Text
[/code]

Let us know how it goes.


Regards,
Drazen