2010-11-01 62 views
1

我试图解密使用CakePHP的安全::加密解密工作不

Security::cipher($strHashedPassword, Configure::read('Security.salt')); 

似乎并没有被给予期望的结果散列字符串。有人对这个有经验么?从文档看来,这应该起作用。

回答

5

请注意,您不能解密散列。根据定义,Hashes是不可逆转的。他们不能解密,因为他们不是加密开始,他们散列。如果你真的想解密一个密码哈希(如AuthComponent所产生的),那么你运气不好。

Security::cipher只能解密字符串加密过为好,在这种情况下,你可以谈论一个密文,不是哈希。

如果你能证明这不打印“测试”:

$cipherText = Security::cipher('test', Configure::read('Security.salt')); 
echo Security::cipher($cipherText, Configure::read('Security.salt')); 

你发现在蛋糕中的错误,很有可能是一个由@infinity连接。否则,你在尝试一些不可能的事情。

+0

但对我来说,下面的代码正在工作......,$ c = Security :: cipher('testing hash',Configure :: read('Security.salt')); $ cc = Security :: cipher($ c,Configure :: read('Security.salt')); echo $ cc; – 2014-01-22 11:39:16

+0

@Vivek正如预期的那样。也许你误解了我写的东西。 – deceze 2014-01-22 12:17:44

+0

@ -deceze。真的很困惑。 – 2014-01-22 12:44:47