in Actionscript 3 i need to compute data (a string, utf-8), using a secret key (a string, utf-8).
This is the data (string) "symbol=LTCBTC&side=BUY&type=LIMIT&timeInForce=GTC&quantity=1&price=0.1&recvWindow=5000×tamp=1499827319559"
This is the secret key (string) "NhqPtmdSJYdKjVHjA7PZj4Mge3R5YNiP1e3UZjInClVN65XAbvqqM6A7H5fATj0j"
This is the result it must come out (string) "c8db56825ae71d6d79447849e617115f4a920fa2acdcab2b053c4b2838bd6b71"
Can someone solve this? (the result is correct, but i don't know the code to arrive at the result).
This is what i have tried so far:
// THE DATA
var dataToEncode:String = "symbol=LTCBTC&side=BUY&type=LIMIT&timeInForce=GTC&quantity=1&price=0.1&recvWindow=5000×tamp=1499827319559";
var byteArrayOfDataToEncode:ByteArray = new ByteArray();
byteArrayOfDataToEncode.writeUTF(dataToEncode); // we write the string into the ByteArray
// THE SECRET KEY
var secretKey:String = "NhqPtmdSJYdKjVHjA7PZj4Mge3R5YNiP1e3UZjInClVN65XAbvqqM6A7H5fATj0j";
var byteArrayOfSecretKey:ByteArray = new ByteArray();
byteArrayOfSecretKey.writeUTF(secretKey); // we write the secret key into the ByteArray
// WE COMPUTE THE SIGNATURE
var HMAC_SHA256:HMAC = new HMAC(new SHA256());
var byteArrayOfResultSignature:ByteArray = HMAC_SHA256.compute(byteArrayOfSecretKey, byteArrayOfDataToEncode);
var resultSignature:String = byteArrayOfResultSignature.readUTF();
// WE SHOW THE RESULT SIGNATURE
trace("The result signature is: "+resultSignature);
This HMAC class is created using this library (AS3Crypto): https://github.com/Atmosphere/ActionScript/blob/master/src/com/hurlant/crypto/hash/HMAC.as
release
folder. Additionally thetester
folder contains a basic sample app. If you don't have Gradle on your system you can hopefully still re-use theMain.as
file as a starting point without preferred setup. – George Profenza