Skip to content

Instantly share code, notes, and snippets.

@nihitx
Created August 4, 2017 07:20
Show Gist options
  • Save nihitx/e3c6b2f1a943f74833ef85ee26eb5793 to your computer and use it in GitHub Desktop.
Save nihitx/e3c6b2f1a943f74833ef85ee26eb5793 to your computer and use it in GitHub Desktop.
<?php
$Key = md5('MasnadIsAwesome');
//Encrypt
function encrypt($String, $Key){
$string = rtrim(base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $Key, $String, MCRYPT_MODE_ECB)));
return $string
}
// Decrypt
function decrypt($String, $key){
$string = rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $Key, base64_decode($String), MCRYPT_MODE_ECB));
return $string;
}
// Change all mysql table to varbinary where the encrption is necessary
### Example of insert statement with encrypt ####
$sql = "INSERT INTO user (name, address) VALUES ('".encrypt($name, $Key)."' , '".encrypt($address, $Key)."')" ;
// Decrypt is easier and it can be done in the function
decrypt('stuff', $Key);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment