这是我在研究 air 的加密方法时发现的一篇文章。
http://help.adobe.com/en_US/AIR/1.5/devappsflex/WS34990ABF-C893-47ec-B813-9C9D9587A398.html
这是加密的规范:高级加密标准 (AES) 和带有 CBC-MAC (CCM) 模式的计数器。
在 PHP 中,您可以使用 mcrypt 库。
mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key, base64_decode($encrypted), MCRYPT_MODE_CBC, $iv)
这是生成安全密钥的逻辑(在动作脚本中):
public static function getEncryptionKey(password:String):ByteArray
{
var bytes:ByteArray = new ByteArray();
bytes.writeUTF(password + "password salt");
bytes.position = 0; // have to reset to 0 for an accurate hash
var hashedKey:String = SHA256.computeDigest(bytes);
var encryptionKey:ByteArray = generateEncryptionKey(hashedKey);
return encryptionKey;
}
private static function generateEncryptionKey(hash:String):ByteArray
{
var result:ByteArray = new ByteArray();
// select a range of 128 bits (32 hex characters) from the hash
// In this case, we'll use the bits starting from position 17
for (var i:uint = 0; i < 32; i += 2)
{
var position:uint = i + 17;
var hex:String = hash.substr(position, 2);
var byte:int = parseInt(hex, 16);
result.writeByte(byte);
}
return result;
}