Created
January 11, 2016 18:14
-
-
Save Saeven/201255d34c8bfaad3517 to your computer and use it in GitHub Desktop.
AES-256 should not be confused with Rijndael-256.
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 | |
| class Foo | |
| { | |
| const COOKIE_KEY = '839914B48AE583605F004C784FEF155B39A2C142AD7A747582160E6C14E7EF16'; | |
| const COOKIE_IV = '864C9BB8032792391B88C76CF73276F2'; | |
| public function encrypt( $what ) | |
| { | |
| $cipher = MCRYPT_RIJNDAEL_128; | |
| $mode = MCRYPT_MODE_CBC; | |
| $key = hex2bin( self::COOKIE_KEY ); | |
| $iv = hex2bin( self::COOKIE_IV ); | |
| return mcrypt_encrypt( $cipher, $key, $what, $mode, $iv ); | |
| } | |
| public function decrypt( $what ) | |
| { | |
| $cipher = MCRYPT_RIJNDAEL_128; | |
| $mode = MCRYPT_MODE_CBC; | |
| $key = hex2bin( self::COOKIE_KEY ); | |
| $iv = hex2bin( self::COOKIE_IV ); | |
| return mcrypt_decrypt( $cipher, $key, $what, $mode, $iv ); | |
| } | |
| } | |
| $f = new Foo(); | |
| $str = bin2hex( $f->encrypt( 'hello there' ) ); | |
| echo $f->decrypt( hex2bin( $str ) ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment