我想用AES-CBC 128-bit对AS3中的字符串进行加密。该怎么做呢?
发布于 2014-04-07 20:12:02
使用AS3Crypto https://code.google.com/p/as3crypto/,下面是代码片段:
//notice that decrKey and decrIV length must be 16 chars long! ex: 1234567890123456
private function encrypt(input:String,decrKey:String,decrIV:String):String
{
var inputBA:ByteArray=Hex.toArray(Hex.fromString(input));
var key:ByteArray = Hex.toArray(Hex.fromString(decrKey));
var pad:IPad = new NullPad();
var aes:ICipher = Crypto.getCipher("aes-cbc", key, pad);
var ivmode:IVMode = aes as IVMode;
ivmode.IV = Hex.toArray(Hex.fromString(decrIV));
aes.encrypt(inputBA);
return Base64.encodeByteArray( inputBA); //if not use Base64 encode, data would be just byteArray
} 注意:这段代码是完全兼容的,例如:与PHP (或C#),下面是PHP的解密。
//notice that $key and $iv length must be 16 chars long! ex: 1234567890123456
function decrypt($data,$key,$iv)
{
$decr= mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key, base64_decode($data), MCRYPT_MODE_CBC, $iv);
return $decr;
} https://stackoverflow.com/questions/22910812
复制相似问题