Created
August 4, 2017 07:20
-
-
Save nihitx/e3c6b2f1a943f74833ef85ee26eb5793 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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