哈希字符串,稍后从哈希中检索


Hash string and retrieve from hash later

是否有任何方法可以散列字符串,并在稍后取消散列?

例如,我想对一个电子邮件地址进行散列以生成一个唯一的链接,并在访问该链接时检索该电子邮件地址。

如你所见,这更多的是混淆而不是散列。

你不能散列和反散列字符串,但可以使用base64_encode和base64_decode做类似的事情:

<?php
$str = 'This is an encoded string';
echo base64_encode($str);
?>
上面的示例将输出:
VGhpcyBpcyBhbiBlbmNvZGVkIHN0cmluZw==

你可以解码:

<?php
$str = 'VGhpcyBpcyBhbiBlbmNvZGVkIHN0cmluZw==';
echo base64_decode($str);
?>
上面的示例将输出:
This is an encoded string

如PHP.net手册所示:

http://php.net/manual/en/function.base64-encode.php

http://php.net/manual/en/function.base64-decode.php

没有解列。哈希是一种单向加密。为此,您可以将电子邮件和散列保存在一个表中,并选择散列等于某值的电子邮件。

id, email, hash
1   a@b.cc  m3jf9s...

SELECT `email` from `activation_table` WHERE `hash` = 'm3jf9s...';

然后显示在页面上