Decrypting strings in Python that were encrypted with MCRYPT_RIJNDAEL_256 in PHP

后端 未结 3 674
失恋的感觉
失恋的感觉 2020-11-30 08:48

I have a function in PHP that encrypts text as follows:

function encrypt($text)
{
    $Key = \"MyKey\";

    return trim(base64_encode(mcrypt_encrypt(MCRYPT_         


        
3条回答
  •  广开言路
    2020-11-30 09:51

    If you're willing to use MCRYPT_RIJNDAEL_128 rather than 256 on the PHP side, this is as simple as:

    from Crypto.Cipher import AES
    import base64
    key="MyKey"
    
    def decrypt(text)
        cipher=AES.new(key)
        return cipher.decrypt(base64.b64decode(text))
    

提交回复
热议问题