Created
March 15, 2016 13:44
-
-
Save umanda/1f176720916ee9b40f74 to your computer and use it in GitHub Desktop.
How to create two way encode/decode methods using use-specific key in PHP
This file contains hidden or 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 = "secret_key"; | |
$data ="String"; | |
// Encodeing | |
$encoded = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5($key), $data, MCRYPT_MODE_CBC, md5(md5($key)))); | |
// Decoding | |
$decoded = rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($key), base64_decode($encoded), MCRYPT_MODE_CBC, md5(md5($key))), "\0"); | |
// Ie. | |
echo $encoded; | |
echo "<br>"; | |
echo $decoded; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment