I wanted to improve a certain wordpress plugin that uses the now obsolete "mcrypt". Instead of it, I would like to use the OpenSSL library to encrypt the submited data, but during the encryption I ran into problems, namely: the openssl_encrypt function returns a different value than mcrypt_encrypt by which the system I am connecting to does not return me the correct data, and its owner has no way to send me logs of what I uploaded to it :(
I've already scoured the internet the length and breadth of the Internet, but have not found a solution. I suspect that the problem is padding, but I can't find a solution. Can you help?
Below are the insides of my PHP object $password, $salt and $iv are obviously changed
class EncryptDebug{
private $algo = 'sha1';
private $password = 'ab4232goodcf423484422c90c3e4aa7c';
private $salt = 'ascastas54490a31';
private $iv = '8947da32awl55kwj'
private $lenght = 16;
private function generate_key(){
return hash_pbkdf2( $this->algo , $this->password , $this->salt, 100, $this->lenght, true );
}
public function encryptSSL($plaintext){
$key = $this->generate_key();
$ciphertext = base64_encode(openssl_encrypt($plaintext, 'AES-128-CBC', $key, OPENSSL_ZERO_PADDING, $this->iv));
return str_replace('+', '%2B', $ciphertext);
}
public function encryptMCRYPT($plaintext){
$key = $this->generate_key();
$ciphertext = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $plaintext, MCRYPT_MODE_CBC, $this->iv));
return str_replace('+', '%2B', $ciphertext);
}
}
Forgot to mention: OPENSSL_ZERO_PADDING returns error. Using OPENSSL_RAW_DATA I'm able to get results similar to mcrypt_encrypt, but the ending is different, example:
OpenSSL: rPzVvF7gaPMA4ADAjHUW8Wy1ThTJG%2BVPdcz5iKAkAwrDTTFTcOpWgWOCh9l9JFZ8WcNzMJ868026TkUxcYJMrQ==
MCRYPT: rPzVvF7gaPMA4ADAjHUW8Wy1ThTJG%2BVPdcz5iKAkAwrDTTFTcOpWgWOCh9l9JFZ8UGVfF091Q9bY61mTRg%2BBSg==