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

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


Lorenz,

Well, I've experimented with ByteArray.writeUTFBytes( 'testtest' ) to avoid
the Hex utility library and it's given me the same results.

I don't think that is the issue, if you have pycrypto installed would you be
able to run the code to encrypt and base64 the string? You could copy and
paste it verbatim into idle, wouldn't be much work at all and it would
really help me out if I knew what the expected output of the python library
should be.

Thanks
Joshua

On Wed, Jan 12, 2011 at 11:45 AM, Lorenz Quack <don at amberfisharts.com>wrote:

> 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
> >
>
> _______________________________________________
> pycrypto mailing list
> pycrypto at lists.dlitz.net
> http://lists.dlitz.net/cgi-bin/mailman/listinfo/pycrypto
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.dlitz.net/pipermail/pycrypto/attachments/20110112/dbd887e7/attachment-0001.htm 


More information about the pycrypto mailing list