How to do AES256 decryption in PHP?

前端 未结 2 2144
孤城傲影
孤城傲影 2020-11-30 08:07

I have an encrypted bit of text that I need to decrypt. It\'s encrypted with AES-256-CBC. I have the encrypted text, key, and iv. However, no matter what I try I just can\'t

2条回答
  •  星月不相逢
    2020-11-30 09:05

    I'm not terribly familiar with this stuff, but it seems like trying MCRYPT_RIJNDAEL_256 in place of MCRYPT_RIJNDAEL_128 would be an obvious next step...

    Edit: You're right -- this isn't what you need. MCRYPT_RIJNDAEL_128 is in fact the right choice. According to the link you provided, your key and IV are twice as long as they should be:

    // How do you do 256-bit AES encryption in PHP vs. 128-bit AES encryption???
    // The answer is:  Give it a key that's 32 bytes long as opposed to 16 bytes long.
    // For example:
    $key256 = '12345678901234561234567890123456';
    $key128 = '1234567890123456';
    
    // Here's our 128-bit IV which is used for both 256-bit and 128-bit keys.
    $iv =  '1234567890123456';
    

提交回复
热议问题