-4

这是我的密码加密代码:

// Create a 256 bit (64 characters) long random salt
// Let's add 'something random' and the username
// to the salt as well for added security
$salt = hash('sha256', uniqid(mt_rand(), true) . 'something random' . strtolower($username));

// Prefix the password with the salt
$hash = $salt . $password;

// Hash the salted password a bunch of times
for ( $i = 0; $i < 100000; $i ++ )
{
    $hash = hash('sha256', $hash);
}

// Prefix the hash with the salt so we can find it back later
$hash = $salt . $hash;

我失去了教程网站。有谁知道如何解密这个加密。非常感谢。感谢你的帮助

4

2 回答 2

9

没有*de*cryption 算法,因为没有*en*cryption 算法。你正在做的是一个hash,这是一个不可逆的操作。这正是重点,您不想存储任何可能让您有机会知道实际秘密密码的内容。

于 2013-08-29T10:50:39.893 回答
2

散列函数与加密不同。检查有关散列的 Wiki。底线是:哈希是一种单向算法。你不能一口气解密它。您可以暴力破解它,但是(尤其是使用 sha256)这需要很长时间。如果您有一台专门用于破解 sha256 哈希的机器,则需要 ~= 10^64 年!如果 10^64 没有意义,这里是完整的数字:

100.000.000.000.000.000.000.000.000.000.000.000.000.000.000.000.000.000.000.000.000.000

即便如此,也不能保证结果是正确的:你最终可能会遇到哈希冲突(google it)。如果你这样做:振作起来,你会是第一个,AFAIK。

有关加密与散列的更多信息,请参阅this answer to a previous SO question

所以答案是:你不能解密(或者更确切地说是去散列)你拥有的东西。

于 2013-08-29T10:53:51.033 回答