[pycrypto] Base64 encoded output differs from pycrypto and as3crypto libraries.

Joshua Strauss joshua.a.strauss at gmail.com
Wed Jan 12 13:07:49 CST 2011


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.dlitz.net/pipermail/pycrypto/attachments/20110112/fd046061/attachment.htm 


More information about the pycrypto mailing list