byteArrayOfDataToEncode

byteArrayOfDataToEncode

这是密钥(字符串)NhqPtmdSJYdKjVHjA7PZj4Mge3R5YNiP1e3UZjInClVN65XAbvqqM6A7H5fATj0j"这是它必须出来的结果(字符串)c8db56825ae71d6d79447849e617115f4a920fa2acdcab2b053c4b2838bd6b71"有人能解决这个问题吗?(结果是正确的,但我不知道得出结果的代码).这是我迄今为止尝试过的://数据var dataToEncode:String = "symbol=LTCBTC&side=BUY&type=LIMIT&timeInForce=GTC&quantity=1&price=0.1&recvWindow=5000&timestamp=1499827319559";var byteArrayOfDataToEncode:ByteArray = new ByteArray();byteArrayOfDataToEncode.writeUTF(dataToEncode);//我们将字符串写入 ByteArray//秘钥var secretKey:String = "NhqPtmdSJYdKjVHjA7PZj4Mge3R5YNiP1e3UZjInClVN65XAbvqqM6A7H5fATj0j";var byteArrayOfSecretKey:ByteArray = new ByteArray();byteArrayOfSecretKey.writeUTF(secretKey);//我们将密钥写入 ByteArray//我们计算签名var HMAC_SHA256:HMAC = new HMAC(new SHA256());var byteArrayOfResultSignature:ByteArray = HMAC_SHA256.compute(byteArrayOfSecretKey, byteArrayOfDataToEncode);var resultSignature:String = byteArrayOfResultSignature.readUTF();//我们显示结果签名trace("结果签名为:"+resultSignature);这个 HMAC 类是使用这个库 (AS3Crypto) 创建的:https://github.com/Atmosphere/ActionScript/blob/master/src/com/hurlant/crypto/hash/HMAC.as 解决方案 感谢评论者,我找到了答案.解决方案是 com.adobe.crypto .As3corelib 中有一个类(你可以在这里下载)https://code.google.com/archive/p/as3corelib/downloads).您必须通过转到文件->"来导入这些文件夹.Actionscript 设置",然后单击源路径,然后添加com"文件夹在那里.您还需要下载 Adob​​e Flex SDK(因为 As3corelib 中的某些类使用了 Flex SDK 中的某些实用程序类),将其解压缩,然后包含 framework.swc 文件(在 adobe flex 的文件夹中搜索,位于 frameworks/libs 文件夹中),转到文件"->Actionscript 设置",然后单击库路径,然后在那里添加 framework.swf.现在你已经准备好了,就像这样:import com.adobe.crypto.*;//导入它,以访问我们需要的类.//然后把这段代码放在你需要的地方var message:String = symbol=LTCBTC&side=BUY&type=LIMIT&timeInForce=GTC&quantity=1&price=0.1&recvWindow=5000&timestamp=1499827319559";var secretKey:String = "NhqPtmdSJYdKjVHjA7PZj4Mge3R5YNiP1e3UZjInClVN65XAbvqqM6A7H5fATj0j";var 签名:String = HMAC.hash(secretKey, message, SHA256) ;trace("签名为:"+signature);希望对您有所帮助,祝您有美好的一天!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&timestamp=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 DATAvar dataToEncode:String = "symbol=LTCBTC&side=BUY&type=LIMIT&timeInForce=GTC&quantity=1&price=0.1&recvWindow=5000&timestamp=1499827319559";var byteArrayOfDataToEncode:ByteArray = new ByteArray();byteArrayOfDataToEncode.writeUTF(dataToEncode); // we write the string into the ByteArray// THE SECRET KEYvar secretKey:String = "NhqPtmdSJYdKjVHjA7PZj4Mge3R5YNiP1e3UZjInClVN65XAbvqqM6A7H5fATj0j";var byteArrayOfSecretKey:ByteArray = new ByteArray();byteArrayOfSecretKey.writeUTF(secretKey); // we write the secret key into the ByteArray// WE COMPUTE THE SIGNATUREvar HMAC_SHA256:HMAC = new HMAC(new SHA256());var byteArrayOfResultSignature:ByteArray = HMAC_SHA256.compute(byteArrayOfSecretKey, byteArrayOfDataToEncode);var resultSignature:String = byteArrayOfResultSignature.readUTF();// WE SHOW THE RESULT SIGNATUREtrace("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 解决方案 I found, thanks to the commentors, the asnwer to this.The solution is com.adobe.crypto .There is a class in the As3corelib (that you can download herehttps://code.google.com/archive/p/as3corelib/downloads). You have to import those folders by going to "File-> Actionscript settings", and the click on the source path and then add the "com" folder there.You will also need to download the Adobe Flex SDK (because some classes in As3corelib use some utility classes in the Flex SDK), unzip it, and then include the framework.swc file (search in the folders of adobe flex, it is in the frameworks/libs folder), going to "File-> Actionscript settings", and the click on the library path and then add the framework.swf there.Now you are ready to do it, like this:import com.adobe.crypto.*; // import this, to have access to the classes we need.// then this code where you need itvar message:String = "symbol=LTCBTC&side=BUY&type=LIMIT&timeInForce=GTC&quantity=1&price=0.1&recvWindow=5000&timestamp=1499827319559";var secretKey:String = "NhqPtmdSJYdKjVHjA7PZj4Mge3R5YNiP1e3UZjInClVN65XAbvqqM6A7H5fATj0j";var signature:String = HMAC.hash(secretKey, message, SHA256) ;trace("The signature is: "+signature);Hope it helps, have a beautiful day! 这篇关于适用于 Adob​​e AIR(桌面)的 AS3 HMAC SHA-256的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
07-30 13:03