afxgroup / as3crypto

Automatically exported from code.google.com/p/as3crypto
0 stars 0 forks source link

Difference between demo outputs and local test outputs #68

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago

Hello,

I have a problem, 

I would like to crypt with HMAC SHA1 algorithm the string "113004281321398000" 
with the key "Mj\{NTA=MTA(5874"

To do so I use AS3CRYPTO demo here crypto:hurlant:com/demo, I choose HMAC 
panel, sha1. Then I paste my key and the string data in text format, I choose 
base64 for output format.

It outputs [B]GJdYxXIlAwT1FdXtaVQIdZmfKJk=[/B]

But Under FLASH CS5 I write this code to crypt :

[CODE]
import com.hurlant.util.Base64;
import com.hurlant.util.Hex;
import com.hurlant.crypto.hash.HMAC;
import com.hurlant.crypto.Crypto;
import com.hurlant.crypto.hash.IHash;
import com.hurlant.crypto.hash.SHA1;

var key_str:String = 'Mj\{NTA=MTA(5874';
var str:String = '113004281321398000';

var key:ByteArray = Hex.toArray(Hex.fromString(key_str));
var pt:ByteArray = Hex.toArray(Hex.fromString(str));

var hmac:HMAC = Crypto.getHMAC('hmac-sha1');
//var hmac:HMAC = new HMAC(new SHA1());

var secret:ByteArray = hmac.compute(key, pt);
var result = Base64.encodeByteArray(secret);
//secret = Hex.fromArray(secret);
trace(result);

[/CODE]

And it outputs [B]HQLQpEclCPFaOp9tdPmKL0UiVLE=[/B]

This is confusing because the outputs are different between the demo and my 
test, I know that the right output is from the demo.

Do you know where is the problem?

Thanks

What version of the product are you using? On what operating system?
1.3, windows

Thanks

Original issue reported on code.google.com by alexandreaazzouz@gmail.com on 17 Nov 2011 at 10:09

GoogleCodeExporter commented 9 years ago
i have the same problem, how did you solve it ?

Original comment by blazee...@gmail.com on 6 Jun 2013 at 10:25

GoogleCodeExporter commented 9 years ago
i solved it by using 

m.writeUTFBytes(msg.text);
instead of 
m.writeUTF(msg.text);

Original comment by blazee...@gmail.com on 6 Jun 2013 at 10:28