OPEN SSL : _encrypt & _decrypt
Documentations
Posté le 28 décembre 2018 dans Documentations par Julien.
Crypter et décrypter une chaine str avec openssl_encrypt() et _decrypt
// ENCRYPT
function judevEncrypt($str){
$password = "OPEN#SSL/è!7";
$str_encrypted = openssl_encrypt ($str, "AES-128-ECB", $password);
return $str_encrypted;
}
// DECRYPT
function judevDecrypt($str){
$password = "OPEN#SSL/è!7";
$str_decrypted = openssl_decrypt ($str, "AES-128-ECB", $password);
return $str_decrypted;
}
// MAIN
$msg = "I love you <3";
$msg_encrypted = judevEncrypt($msg);
$msg_decrypted = judevDecrypt($msg_encrypted);
echo( $msg_encrypted ); // "tP/g3HN76Ch1b0bUehQVjQ=="
echo( $msg_decrypted ); // "I love you <3"