2010-11-01 28 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