Skip to content

Instantly share code, notes, and snippets.

@umanda
Created March 15, 2016 13:44
Show Gist options
  • Save umanda/1f176720916ee9b40f74 to your computer and use it in GitHub Desktop.
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
<?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