0

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.

Actionscript 3:

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.

Python:

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.

Actionscript 3:

var b:ByteArray = new ByteArray();
b.writeUTFBytes( 'testtest' );
dbg( Base64.encodeByteArray( b ) );

Yields...

dGVzdHRlc3Q=

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?

Artjom B.
  • 61,146
  • 24
  • 125
  • 222

1 Answers1

0

The problem might be in padding. ActionScript uses no padding, but Py doesn't show what padding it uses. So, it can be the reason. Try another padding (PKCS#5 for instance) with actionscript.

Nickolay Olshevsky
  • 13,706
  • 1
  • 34
  • 48