2
我存儲用戶名,密碼和安全令牌使用CodeIgniter的編碼方法類似 -如何在使用CodeIgniter編碼進行編碼時在python中解碼?
$this->load->library('encrypt');
//...
$password = $this->encrypt->encode($rows["password"]);
//Then save it in password column of user_credentials table.
現在,蟒蛇,我想解碼此編碼的密碼。我一直試圖用python的hashlib來解碼它,但我無法做到。
我想這是因爲CI的加密庫做比MD5更在受密碼
function encode($string, $key = '')
{
$key = $this->get_key($key);
if ($this->_mcrypt_exists === TRUE)
{
$enc = $this->mcrypt_encode($string, $key);
}
else
{
$enc = $this->_xor_encode($string, $key);
}
return base64_encode($enc);
}
function decode($string, $key = '')
{
$key = $this->get_key($key);
if (preg_match('/[^a-zA-Z0-9\/\+=]/', $string))
{
return FALSE;
}
$dec = base64_decode($string);
if ($this->_mcrypt_exists === TRUE)
{
if (($dec = $this->mcrypt_decode($dec, $key)) === FALSE)
{
return FALSE;
}
}
else
{
$dec = $this->_xor_decode($dec, $key);
}
return $dec;
}
我應該如何解碼呢?我需要在python中編寫上面的解碼函數。請幫忙。
嗨,從您給我的鏈接安裝此庫。當我在python提示符下輸入mcrypt時,它說'mcrypt'模塊不可用。我搞不清楚了。 – Hussain 2013-02-26 07:05:10
嗨,我已經開始從解碼CI到Python編寫解碼。什麼是等效於CI的'_xor_decode'的python。請幫忙。我即將稱之爲完成。 – Hussain 2013-02-26 07:46:03
檢查您的PYTHONPATH以確保Python能夠找到該模塊。您也可能需要安裝libmcrypt。 [這是一些端口](http://mcrypt.hellug.gr/lib/index.html) – 2013-02-26 08:57:21