Decrypting AES with Javascript CryptoJS after encrypting with PHP mcrypt

前端 未结 1 1603
梦谈多话
梦谈多话 2021-01-07 05:52

Encrypting in PHP with mcrypt



        
相关标签:
1条回答
  • 2021-01-07 06:23

    SOLVED

    Note: I found out that "MCRYPT_RIJNDAEL_256" in PHP's mcrypt is NOT included in AES. It uses the Rijndael method, BUT with a 256-bit block size (not included in AES). So, CryptoJS does not handle 256-bit block sizes for Rijndael. Thanks, GregS

    Nonetheless, I found an implementation that successfully decrypted the ciphertext I get from running my PHP mcrypt function above, using MCRYPT_RIJNDAEL_256 (Rijndael, 256-bit block size, with 256-bit key/32-byte key).

    Here it is: https://code.google.com/p/js-mcrypt/

    <script>
    var encrypted = 'nYoFAiyDARVSI09lH/IPdim5TvE51izVjk6sc2AK9Rg=';
    var key = 'd4b494e4502a62edd695a903a94c2701';
    var iv = '02f30dffbb0d084755f438f7d8be4a7d';
    var decrypted = mcrypt.Decrypt(atob(encrypted), iv, key, 'rijndael-256', 'cbc');
    </script>
    

    I hope this helps someone as I spent a week of my spare time trying to figure this out and almost giving up.

    0 讨论(0)
提交回复
热议问题