Last active
January 8, 2022 16:55
-
-
Save napolux/0f62173c849941899956 to your computer and use it in GitHub Desktop.
Simple reversible encryption
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 | |
// From a StackOverflow answer... | |
// I can't find the original link :-( | |
class StringEncryption { | |
const ENCRYPTION_KEY = "She's a killer queeeeeeeeen!"; | |
public function encode($url = '') { | |
return base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5(self::ENCRYPTION_KEY), $url, MCRYPT_MODE_CBC, md5(md5(self::ENCRYPTION_KEY)))); | |
} | |
public function decode($string = '') { | |
$return = rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5(self::ENCRYPTION_KEY), base64_decode($string), MCRYPT_MODE_CBC, md5(md5(self::ENCRYPTION_KEY))), "\0"); | |
return (ctype_print($return)) ? $return : false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The Mcrypt functions have been deprecated as of PHP 7.1.0 (https://www.php.net/manual/en/function.mcrypt-encrypt.php) - so I'd suggest against using this function for all currently supported versions of PHP.