I have this code in PHP (can't modify)
<?php $myPlain = "123456789012345678900000"; $myKey = md5($myPlain, true); $myKey .= substr($myKey, 0,8); $encrypted = openssl_encrypt($myPlain, 'des-ede3', $myKey, OPENSSL_RAW_DATA); print(base64_encode($encrypted)); This code returns
FTYDrZTZMjVBv5Fk/xcfFxJASaizzrmoPts7fGDvWjc= When I try to replicate this in NodeJS
function testEde3(myKey, myPlain) { try { let md5Key = crypto.createHash('md5').update(myKey, 'utf-8').digest("base64").substr(0, 24); console.log(md5Key); //outputs 4o1aJrSWN3bSfjuIX6VXgA== console.log(md5Key.length); //outputs 24 const cipher = crypto.createCipheriv('des-ede3', md5Key, null); let encrypted = cipher.update(myPlain, 'utf8', 'base64'); encrypted += cipher.final('base64'); return encrypted; } catch ( ex ) { return ex; } } const myKey = "123456789012345678900000"; const myPlain = "123456789012345678900000"; const hash = testEd3(myKey, myPlain); console.log(`Hash is: ${hash}`); The output is
Hash is: lDQX9OGsopKOt6P9WQwekGsKDQGFpfGW50zbs3HrOfQ= I'm thinking the problem is on MD5. If I try to encrypt without md5, the results are the same.
Thanks