暗号化されたデータを戻す場合は
どうしたらいいのでしょうか??
<?
$key = ”sockpuppet”;
$msg = ”This is a super top-secret message.”;
$crypted = mcrypt_ecb(MCRYPT_LOKI97, $key, $msg, MCRYPT_ENCRYPT);
$crypted = bin2hex($crypted);
echo ”$crypted”;
?>
<?
$key = ”sockpuppet”;
$msg = ”This is a super top-secret message.”;
/////////
$size = mcrypt_get_iv_size(MCRYPT_LOKI97, MCRYPT_MODE_ECB);
$iv = mcrypt_create_iv($size, MCRYPT_RAND);
/////////
$crypted = mcrypt_ecb(MCRYPT_LOKI97, $key, $msg, MCRYPT_ENCRYPT,$iv);
$crypted = bin2hex($crypted);
echo ”$crypted”;
?>
<hr>
<?php
$decrypted = pack(”H*”, $crypted);
$decrypted = mcrypt_ecb(MCRYPT_LOKI97, $key, $decrypted, MCRYPT_DECRYPT,$iv);
echo ”$decrypted”;
?>
なお
$size = mcrypt_get_iv_size(MCRYPT_LOKI97, MCRYPT_MODE_ECB);
$iv = mcrypt_create_iv($size, MCRYPT_RAND);
と最後の引数$ivは、libmcrypt 2.2.x のときは不要です。
ありがとうございます。
出来ました。