我有一个 django 应用程序,它为 Flash 应用程序提供加密的媒体文件。python中的加密是使用PyCrypto完成的(我也包括描述以防万一):
def encrypt_aes(key, text):
try:
raw = _pad(text)
iv = Random.new().read(AES.block_size)
cipher = AES.new(key, AES.MODE_CBC, iv)
return base64.b64encode(iv + cipher.encrypt(raw))
except Exception as e:
print e.message
return text
def decrypt_aes(key, text):
try:
enc = base64.b64decode(text)
iv = enc[:AES.block_size]
cipher = AES.new(key, AES.MODE_CBC, iv)
return _unpad(cipher.decrypt(enc[AES.block_size:]))
except Exception as e:
print e.message
return text
def _pad(s):
bs = 16
return s + (bs - len(s) % bs) * chr(bs - len(s) % bs)
def _unpad(s):
return s[:-ord(s[len(s) - 1:])]
我还无法解密 Python 提供的媒体文件( GreenSock 使用LoaderMax下载,使用“DataLoader”)。我的 AS3 代码(使用AS3Crypto)如下:
public static function decipher(_key:String):void{
key=_key;
cipher = Crypto.getCipher("simple-aes-cbc", Hex.toArray(key));
cipher.decrypt(ByteArray(_content));
}
我明白了
RangeError:错误 #2006
一种怀疑是在 Python 中我有 64 位基础,但我认为AS3 ByteArray 是 32 位基础。我已经尝试了以下方法,但得到了相同的错误。
cipher.decrypt(ByteArray(com.hurlant.util.Base64.decodeToByteArray(_content)));
另一个怀疑是我没有从_content中适当地删除“填充”/适当地设置我的IV(这是由我必须从_content中删除的填充指定的)。然而,这应该通过那个“简单”的语句来完成。我一直在尝试这个,但没有成功:
var pad:IPad = new PKCS5
cipher = Crypto.getCipher("simple-aes", Hex.toArray(key),pad);
pad.setBlockSize(cipher.getBlockSize());
谁能建议我如何解决这个问题?:)
非常感谢!