0

PHPでデータを暗号化および復号化する方法は?

これまでの私のコードは次のとおりです:-

function encrypter($plaintext)
{
    $plaintext = strtolower($plaintext);
    $crypttext = mcrypt_encrypt(MCRYPT_RIJNDAEL_256,FLENCKEY,$plaintext,MCRYPT_MODE_ECB);    
    return trim(base64_encode($crypttext));
}

function decrypter($crypttext)
{
    $crypttext = base64_decode($crypttext);    
    $plaintext = mcrypt_decrypt(MCRYPT_RIJNDAEL_256,FLENCKEY,$crypttext,MCRYPT_MODE_ECB);    
    return trim($crypttext);
}

$test = "abc@gmail.com";

エコー暗号化 (テスト);

出力は

iLmUJHKPjPmA9vY0jfQ51qGpLPWC/5bTYWFDOj7Hr08=

エコー復号化 (テスト);

出力は

��-
4

5 に答える 5

2

decrypter()関数で、間違ったデータを返します。

$plaintext次の代わりに戻る必要があり$crypttextます。

function decrypter($crypttext)
{
    $crypttext = base64_decode($crypttext);    
    $plaintext = mcrypt_decrypt(MCRYPT_RIJNDAEL_256,FLENCKEY,$crypttext,MCRYPT_MODE_ECB);    
    //return trim($crypttext);
    return trim($plaintext);
}
于 2013-09-26T06:55:54.497 に答える