5

PHP代码:

$key = "12345678abcdefgh12345678abcdefgh";
$iv = "12345678abcdefgh";
$plaindata = "This is a test string.";

$enc = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $plaindata, MCRYPT_MODE_CBC, $iv));

echo($enc);

结果:

QBN0Yue3D9hBrBuD01n5KWG+lv2doMf97cKm/AeusAI=

如何在 Python 中解密?

4

2 回答 2

7

尝试这样的事情(尽管我确实安装了 PyCrypto)

from Crypto.Cipher import AES
import base64

AES.key_size=128
iv="your iv"
key="your key"
crypt_object=AES.new(key=key,mode=AES.MODE_CBC,IV=iv)

decoded=base64.b64decode(plain) # your ecrypted and encoded text goes here
decrypted=crypt_object.decrypt(decoded)

这将带来解码后的文本,但它将用字节填充,使其大小为 16 的倍数。

您可能应该决定一个适当的填充方案,然后相应地删除它

于 2012-05-10T13:27:41.340 回答
-9

阅读手册,它的文档很好。

data = base64.b64decode('QBN0Yue3D9hBrBuD01n5KWG+lv2doMf97cKm/AeusAI=')
于 2012-05-10T12:54:29.123 回答