Skip to content

Instantly share code, notes, and snippets.

@rovizon
Created August 31, 2018 11:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rovizon/9cd3f3b2fc7dd146b77f44d054df1d47 to your computer and use it in GitHub Desktop.
Save rovizon/9cd3f3b2fc7dd146b77f44d054df1d47 to your computer and use it in GitHub Desktop.
Simple crypt string
<?php
function scrypt( $string, $action = 'e' ) {
// you may change these values to your own
$secret_key = 'my_simple_secret_key';
$secret_iv = 'my_simple_secret_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;
}
var_dump(scrypt('QXBkRzd1Ym1zZDBKU1dRWGRoOVFwZz09', 'd'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment