Skip to content

Instantly share code, notes, and snippets.

@gouf
Created March 14, 2013 08:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gouf/5159716 to your computer and use it in GitHub Desktop.
Save gouf/5159716 to your computer and use it in GitHub Desktop.
PHP でテキスト暗号化・復号
<?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