128 bit blowfish algorithm - WeOnlyDo Discussion board

128 bit blowfish algorithm (General questions)

by sovan, Monday, July 31, 2006, 10:37 (6690 days ago)

Hi there,

I am interested in your product if it gives me what I am after.

I am trying to use your 128 bit Blowfish Encryption, but I am not getting the desired result.

I had used TurboPower Blowfish encryption in my Windows Application and I got this result.

The key we used is - LQSesirpretnENAMATNEC
The String we had encrypted was 1271. and the result I got was - bnWPAaViYy8=

But by using your component to do it I get - STJ2qF6qtxs=.
This is not the result what I am expecting
I am using this code

Dim crypt As New wodCryptCom
Dim i_blob As New MemBlob
Dim o_blob As New MemBlob
i_blob.FromBase64( 1271 )
crypt.Type = CryptoTypes.Blowfish
crypt.SecretKey = LQSesirpretnENAMATNEC
crypt.Optimized = False
crypt.Padding = WODCRYPTCOMLib.CryptoPadding.PadPKCS7
' WODSSHKeyLib.Keys(k = New WODSSHKeyLib.KeysClass)
' k.FromXmlString(m_RSA.ToXmlString(True))
crypt.Encrypt(i_blob, o_blob)
Dim str As String = o_blob.ToBase64
Response.Write(str)
Response.Write( <br> )
i_blob.FromBase64(str)
crypt.Decrypt(i_blob, o_blob)
Response.Write(o_blob.ToBase64)

Please advice how do i get the same result as I am getting in my Windows Application.

Regards
Sovan

Re: 128 bit blowfish algorithm

by wodDamir, Monday, July 31, 2006, 12:02 (6690 days ago) @ sovan

Hi sovan,

Have you perhaps tried our samples that come with the installation package? Do they help?

Regards,
Damba

Re: 128 bit blowfish algorithm

by sovan, Monday, July 31, 2006, 13:46 (6690 days ago) @ wodDamir

Yes, the avobe coding is successfully run in my asp.net project.
but client requirement is what i have mentioned in first post.
i have developed this application using your online help doc and .pdf file. but my aim is to match the result with client requirement.
sovan

Hi sovan,

Have you perhaps tried our samples that come with the installation package? Do they help?

Regards,
Damba

Re: 128 bit blowfish algorithm

by wodDamir, Monday, July 31, 2006, 14:40 (6690 days ago) @ sovan

Hi Sovan,

Are you 100 sure you're using the right SecretKey? Perhaps the key was generated with some other key or you misspelled it?

I replaced the following line of your code:

i_blob.FromBase64( 1271 )

with:

i_blob = 1271

and i've got 7irgANSRD1E= as a result.

Re: 128 bit blowfish algorithm

by wodSupport, Monday, July 31, 2006, 16:57 (6690 days ago) @ wodDamir

Sovan,

I must ask one more thing. I see you mention '128 bit' blowfish algorithm. If it's 128 bit, you would need to have 128 bit key too - but you have large 168 bit key (21 bytes * 8). Perhaps your other tool cuts off the key after 16 bytes?

Kreso

Re: 128 bit blowfish algorithm

by sovan, Tuesday, August 01, 2006, 09:42 (6689 days ago) @ wodSupport

I have applied five 128 bit blowfish algorithm
all have same key and password.
but all gives different result.


Result of Blowfish algo

Key-LQSesirpretnENAMATNEC
Password- 1271

1.Easybyte: /Q1v9xIvNyA=

2.Ezcrypto: BVhrBb60XsI=

3.Chilkat: ELEELs54Ro7zZQVTVENuXA==

4.Inbyte: bwUMjzVJ0Ho=

5.WodCrypt: G+SXAmNfqqQ= key-CENTAMAN

why this?
there are more than one component in market but all gives different result. Till now i wont find my required result
sovan

Sovan,

I must ask one more thing. I see you mention '128 bit' blowfish algorithm. If it's 128 bit, you would need to have 128 bit key too - but you have large 168 bit key (21 bytes * 8). Perhaps your other tool cuts off the key after 16 bytes?

Kreso

Re: 128 bit blowfish algorithm

by wodSupport, Tuesday, August 01, 2006, 09:46 (6689 days ago) @ sovan

Sovan,

that's not 128bit. It all depends on the lenght of the secret key. You must use 16 bytes key (128bit) to have 128bit Blowfish.

BTW in your code you specify 'SecretKey' and 'Password'? Perhaps you mixed them? Perhaps you used Base64 to read it in some cases, and forgot to use it in another cases?

Do you use CBC mode? If so, is your InitVector the same in all cases?

Kreso

Re: 128 bit blowfish algorithm

by sovan, Tuesday, August 01, 2006, 12:54 (6689 days ago) @ wodSupport

I have applied what you have send me

the coding follows:
Dim crypt As New wodCryptCom
Dim i_blob As New MemBlob
Dim o_blob As New MemBlob
'i_blob.Text = 1271
i_blob.FromBase64( 1271 )
crypt.Type = CryptoTypes.Blowfish
crypt.SecretKey = 1111222233334444 '16byte key
crypt.Optimized = False
crypt.Padding = WODCRYPTCOMLib.CryptoPadding.PadPKCS7
crypt.Encrypt(i_blob, o_blob)
Dim str As String = o_blob.ToBase64
Response.Write(str)
Response.Write( <br> )
i_blob.FromBase64(str)
crypt.Decrypt(i_blob, o_blob)
Response.Write(o_blob.ToBase64)

the result is:
Encrypted value: gcnw/sxIYbM=
decrypted value: 1271

it runs fine but
We are using Product of TurboPower
it gives result:
Encrypted value: Hft4sSl5T5s=
decrypted value: 1271

so why these two encrypted values are not matched.
if this due to change of value to or from base64?
if there any error in avove coding?
sovan

Sovan,

that's not 128bit. It all depends on the lenght of the secret key. You must use 16 bytes key (128bit) to have 128bit Blowfish.

BTW in your code you specify 'SecretKey' and 'Password'? Perhaps you mixed them? Perhaps you used Base64 to read it in some cases, and forgot to use it in another cases?

Do you use CBC mode? If so, is your InitVector the same in all cases?

Kreso

Re: 128 bit blowfish algorithm

by wodSupport, Tuesday, August 01, 2006, 15:33 (6689 days ago) @ sovan

Sovan,

I can't tell you about other tool(s) you use, but if I go to reference tests at http://www.schneier.com/code/vectors.txt and try them out with our code, they work correctly. For example, here's code for first test (key 16 zeros hex, data 16 zeros hex, result should be 4EF997456198DD78 hex):[code]Dim c As New wodCryptCom

Dim intest As New MemBlob
intest.FromHex ( 0000000000000000 )

Dim inkey As New MemBlob
inkey.FromHex ( 0000000000000000 )
c.SecretKey = inkey
c.Type = Blowfish
c.Optimized = False

Dim outtest As New MemBlob
c.Encrypt intest, outtest
Debug.Print outtest.ToHex[/code] Hope this helps!

Kreso

Re: 128 bit blowfish algorithm

by sovan, Wednesday, August 02, 2006, 06:46 (6688 days ago) @ wodSupport

i have applied your coding

coding follows:
Dim c As New wodCryptCom

Dim intest As New MemBlob
intest.FromHex( FFFFFFFFFFFFFFFF )

Dim inkey As New MemBlob
inkey.FromHex( FFFFFFFFFFFFFFFF )
c.SecretKey = inkey
c.Type = CryptoTypes.Blowfish
c.Optimized = False

Dim outtest As New MemBlob
c.Encrypt(intest, outtest)
'Debug.Print(outtest.ToHex)
Response.Write(outtest.ToHex)

the result is :51866fd5b85ecb8a

why those alphabets are in lower case?
from chilkat i have found:51866FD5B85ECB8A proper result

sovan

Sovan,

I can't tell you about other tool(s) you use, but if I go to reference tests at http://www.schneier.com/code/vectors.txt and try them out with our code, they work correctly. For example, here's code for first test (key 16 zeros hex, data 16 zeros hex, result should be 4EF997456198DD78 hex):[code]Dim c As New wodCryptCom

Dim intest As New MemBlob
intest.FromHex ( 0000000000000000 )

Dim inkey As New MemBlob
inkey.FromHex ( 0000000000000000 )
c.SecretKey = inkey
c.Type = Blowfish
c.Optimized = False

Dim outtest As New MemBlob
c.Encrypt intest, outtest
Debug.Print outtest.ToHex[/code] Hope this helps!

Kreso

Re: 128 bit blowfish algorithm

by wodDamir, Wednesday, August 02, 2006, 08:46 (6688 days ago) @ sovan

Hi sovan,

You can easily parse that value if you enter code similiar to this:

---------------------------------------
Debug.Print UCase(outtest.ToHex)
---------------------------------------

That way you'll get the result in UpperCase.

Hope i helped.

Regards,
Damba

Re: 128 bit blowfish algorithm

by sovan, Wednesday, August 02, 2006, 10:11 (6688 days ago) @ wodDamir

now, we have matched result of two component
on setting key bytes and clear bytes = FFFFFFFFFFFFFFFF
WodCrypt= 51866FD5B85ECB8A
chilkat= 51866FD5B85ECB8A

now i just change the coding follows:
Dim c As New wodCryptCom

Dim intest As New MemBlob
intest.FromBase64( FFFFFFFFFFFFFFFF )

Dim inkey As New MemBlob
inkey.FromBase64( FFFFFFFFFFFFFFFF )
c.SecretKey = inkey
c.Type = CryptoTypes.Blowfish
c.Optimized = False

Dim outtest As New MemBlob
c.Encrypt(intest, outtest)
Response.Write(outtest.ToBase64)

i just replace Hex by Base64 in both cases
i have got result

WoCrypt: Mw0+fA/9NDiGj9YcrWmFEw==
chilkat: p+TUcch4d0Q=

so the algorithm is correct. but why this changes occurs in Base64 for two different component?
the interesting thing is that no one matches with TurboPower component. it gives result : o9C9KMdGbBmj0L0ox0ZsGeic+26BACpd
i have just puzzeled which is perfect product for our web based application?

sovan

Hi sovan,

You can easily parse that value if you enter code similiar to this:

---------------------------------------
Debug.Print UCase(outtest.ToHex)
---------------------------------------

That way you'll get the result in UpperCase.

Hope i helped.

Regards,
Damba