Welcome aboard! We are happy you are here and wish you good net-raft!
<?php
function encrypt_decrypt($string_enc, $action='encrypt') {
$encrypt_method = "AES-256-CBC";
$user_secret_key = 'AA74CDCC2BBRT935136HH7B63C27'; // user define private key
$user_secret_iv = '5fgf5HJ5g27'; // user define secret key
$key = hash('sha256', $user_secret_key);
$iv = substr(hash('sha256', $user_secret_iv), 0, 16); // sha256 is hash_hmac_algo
if( $action == 'encrypt' ) {
$output = openssl_encrypt($string_enc, $encrypt_method, $key, 0, $iv);
$output = base64_encode($output);
}
else if( $action == 'decrypt' ){
$output = openssl_decrypt(base64_decode($string_enc), $encrypt_method, $key, 0, $iv);
}
return $output;
}
echo "Your Encrypted password is => ". $pwd = encrypt_decrypt('spaceo', 'encrypt');
echo '<br/>';
echo "Your Decrypted password is => ". encrypt_decrypt($pwd, 'decrypt');
?>
The most helpful PHP solutions
detect browser phpPHP Click to see more ... 4.6K 408