[pycrypto] Base64 encoded output differs from pycrypto and as3crypto libraries.
Lorenz Quack
don at amberfisharts.com
Wed Jan 12 13:45:00 CST 2011
Hey Joshua,
I haven't used as3crypto (or any as3 for that matter) nor the pycrypto.blowfish. So basicly I'm just wildly guessing
here. I was wondering if you made sure that this "Hex" thing in your as3 code isn't messing up things?
because in you base64 test you don't use that.
cheers,
//Lorenz
On 01/12/2011 08:07 PM, Joshua Strauss wrote:
> I'm trying to use symmetric encryption to pass data from actionscript 3 (client) to python (server).
>
> The libraries I'm using are as3crypto and pycrypto.
>
> I'm not sure if I'm using these libraries correctly, here's the action script 3 code.
>
> private function testOnInit():void {
> var t_toEnc:String = 'testtest';
> var t_byAry:ByteArray = Hex.toArray( Hex.fromString( t_toEnc ) );
> var t_key:ByteArray = Hex.toArray( Hex.fromString( 'Thisisthekey' ) );
> var t_cbc:CBCMode = new CBCMode( new BlowFishKey( t_key ), new NullPad );
> var t_enc:String;
> t_cbc.IV = Hex.toArray( '30313233' );
> t_cbc.encrypt( t_byAry );
> t_enc = Base64.encodeByteArray( t_byAry );
> dbg( 'b64 encrypted string ' + t_enc ); //this is just a debugging function we use in our code.
> }
>
> This is the base64 encoded output of the function above.
>
> xvVqLzV5TU4=
>
> Now, using the same key, initialization vector, and algorithm from the pycrypto library gives me different output.
>
> Here's the python code.
>
> >>> from Crypto.Cipher import Blowfish
> >>> B = Blowfish.new( 'Thisisthekey', Blowfish.MODE_CBC, '30313233' )
> >>> S = 'testtest'
> >>> X = B.encrypt( S )
> >>> import base64
> >>> Y = base64.b64encode( X )
> >>> print Y
>
> I82NQEkSHhE=
>
> I'm pretty sure that I'm doing something wrong with the encryption process because I can base64 encode 'testtest' on
> both libraries and receive the same output.
>
> Here's as3
>
> var b:ByteArray = new ByteArray();
> b.writeUTFBytes( 'testtest' );
> dbg( Base64.encodeByteArray( b ) );
>
> Yields...
>
> dGVzdHRlc3Q=
>
> Here's the python
>
> >>> T = 'testtest'
> >>> print base64.b64encode( T )
>
> Yields…
>
> dGVzdHRlc3Q=
>
> Could someone please encrypt and base64encode the same string with the same IV in either python or actionscript, so I
> know which library is actually producing the correct output?
>
> Any assistance with this problem would be greatly appreciated, I'm stuck and don't know how to proceed from here.
>
> Thank you
> Joshua
>
More information about the pycrypto
mailing list