Encrypt Dycrypt in php
PHP Code
Now you can make your own PHP encryption-decryption function using PHP
Function:
function my_crypt( $string, $action = 'e' ) {
$secret_key = 'make ur own key';
$secret_iv = 'make your own iv';
$output = false;
$encrypt_method = "AES-256-CBC";
$key = hash( 'sha256', $secret_key );
$iv = substr( hash( 'sha256', $secret_iv ), 0, 16 );
if( $action == 'e' ) {
$output = base64_encode( openssl_encrypt( $string, $encrypt_method, $key, 0, $iv ) );
}
else if( $action == 'd' ){
$output = openssl_decrypt( base64_decode( $string ), $encrypt_method, $key, 0, $iv );
}
return $output;
}
Used:
// encrypt
echo my_crypt("hello world", "e");
// output YmVuUEhBdXRHbDNEMm84aTZHQ05jdz09
// decrypt
echo my_crypt("YmVuUEhBdXRHbDNEMm84aTZHQ05jdz09", "d");
// output hello world
Comments
Post a Comment