2

I store userNames, passwords and security-tokens using CodeIgniter's encode method like -

$this->load->library('encrypt');
//...
$password = $this->encrypt->encode($rows["password"]);
//Then save it in password column of user_credentials table.

Now, In python, I want to decode this encoded password. I have been trying to decode it with python's hashlib, but I am not able to.

I think it is because CI's encrypt library does more than md5 on the password-

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;
}

How should I decode it? I need to write above decode function in python. Please help.

1 Answer 1

1

Take a look at CI's system/libraries/Encrypt.php and check out how mcrypt_decode and _remove_cipher_noise work. There's a python interface to the mcrypt library available. Good hunting.

Sign up to request clarification or add additional context in comments.

6 Comments

Hi, Installed this library from the link you gave me. When I do import mcrypt in python prompt it says the mcrypt module is not available. I am lost.
Hi, I have started to write decode in python from decode of CI. What is python equivalent to CI's _xor_decode . Please help. I am about to call it done.
Check your PYTHONPATH to make sure Python can find the module. You may need to install libmcrypt as well. Here's some ports
BTW, from the CI docs: "The Encryption Class provides two-way data encryption. It uses a scheme that either compiles the message using a randomly hashed bitwise XOR encoding scheme, or is encrypted using the Mcrypt library. If Mcrypt is not available on your server the encoded message will still provide a reasonable degree of security for encrypted sessions or other such "light" purposes. If Mcrypt is available, you'll be provided with a high degree of security appropriate for storage." So best to go with mcrypt if you can
Hi, $this->_mcrypt_exists = FALSE . So In python I only have to do the xor part. So I need a method equivalent to _xor_decode from php. I have written python decode method till this point and searching for xor. Do you know such method?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.