node-mcrypt icon indicating copy to clipboard operation
node-mcrypt copied to clipboard

decrypt text encrypted through php encrypt

Open pmaganti opened this issue 10 years ago • 2 comments

We are re-writing our php app to node js app and trying to decrypt the password which is encrypted using php encrypt by twofish.

$this->load->library('encrypt'); 
$this->encrypt->set_cipher(MCRYPT_TWOFISH); 
$encodedPass = $this->encrypt->encode($_POST['password']);

Mode defaulted to cbc.

Here is my decrypt code using in node js:

        var ivAndCiphertext = new Buffer(ENCRYPTED_PASSWORD, 'base64');
        var twofishCbc = new MCrypt('twofish', 'cbc');
        var ivSize = twofishCbc.getIvSize();
        var iv = new Buffer(ivSize);
        var cipherText = new Buffer(ivAndCiphertext.length - ivSize);

        ivAndCiphertext.copy(iv, 0, 0, ivSize);
        ivAndCiphertext.copy(cipherText, 0, ivSize);

        twofishCbc.open('somekey', iv);

        console.log(twofishCbc.decrypt(cipherText).toString());

I am stuck here. Could you please help me how to decrypt using mcrypt library.

pmaganti avatar Oct 28 '15 13:10 pmaganti

I dont know that php framework how could handle iv. Stackoverflow can be helpful than bug report. Thanks

tugrul avatar Nov 10 '15 14:11 tugrul

I wasn't able to mark it as question. Can you mark this as question and keep it opened so that someone can help if they did this earlier.

PHP framework is CodeIgniter mcrypt library. I too posted in stackoverflow.

pmaganti avatar Nov 10 '15 14:11 pmaganti