[wd_asp elements=’search’ ratio=’100%’ id=1]

Encrypt/Decrypt GET Urls

10th October 2014

Php - Strings

php codehaven

When sending get urls, encrypt and decrypt using this method….

$dog = "bouncer";
function encryptor($action, $string) {
$output = false;

$encrypt_method = "AES-256-CBC";
//pls set your unique hashing key
$secret_key = '9jju89u8h77$BG6';
$salt = 'hgug78y£tY';

// hash
$key = hash('sha256', $secret_key);

// iv - encrypt method AES-256-CBC expects 16 bytes - else you will get a warning
$iv = substr(hash('sha256', $salt), 0, 16);

//do the encyption given text/string/number
if( $action == 'encrypt' ) {
$output = openssl_encrypt($string, $encrypt_method, $key, 0, $iv);
$output = base64_encode($output);
}
else if( $action == 'decrypt' ){
//decrypt the given text/string/number
$output = openssl_decrypt(base64_decode($string), $encrypt_method, $key, 0, $iv);
}

return $output;
}

// echo encryptor('encrypt', $dog);

echo encryptor('decrypt','V2t5b3d0YzBWOGoralhBWGZHT3lCZz09');