PHP, 3DES encryption and decryption, see the following code encryption mode ECB, encryption method
/**
* Encrypt
* @param $data
* @return string
* @DateTime 2019-02-22 10:28
*/
public function encrypt($data, $key)
{
$encData = openssl_encrypt($data, 'DES-EDE3', $key, OPENSSL_RAW_DATA);
$encData = base64_encode($encData);
return $encData;
}
/**
* Decrypt
* @param $data
* @return string
* @DateTime 2019-02-22 10:30
*/
public function decrypt($data, $key)
{
$data = base64_decode($data);
$decData = openssl_decrypt($data, 'DES-EDE3', $key, OPENSSL_RAW_DATA);
return $decData;
}
Why not mcrypt use openssl?
ps: the PHP7.1 removed mcrypt, and my PHP version 7.2, so you want to use openssl
Why encryption mode with DES-EDE3, rather than similar DES-EDE3-ECB this
ps: openssl does not support the ECB mode
Pictures from the original segment Fault 3DES in the end not to support ECB mode?