Created
March 14, 2013 08:17
-
-
Save gouf/5159716 to your computer and use it in GitHub Desktop.
PHP でテキスト暗号化・復号
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 | |
// 暗号化準備 | |
$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB); | |
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND); | |
$plainText = 'This is plain text.'; | |
// Crypt: | |
$cd = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $plainText, MCRYPT_MODE_ECB, $iv); | |
$cd = base64_encode($cd); | |
// When decrypt: | |
// $dd = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, base64_decode('AcBPEAWAGwOo7Q4Ty36SZISBd3E4I4os58ytvEJoRYk='), MCRYPT_MODE_ECB); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment