Search code examples
phpnode.jsmcryptcryptojscfb-mode

mcrypt_encrypt in CFB mode function in CryptoJS


I'm trying to convert an mcrypt_encrypt function written in php to node.js, I am using CryptoJS in node.js and tried all kinds of config options and I am not having any luck figuring this thing out.

PHP CODE:

base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_128,md5($secretKey),$ldapPwd,MCRYPT_MODE_CFB,$initialVector))

JavaScript Code That I tried do not know what I am doing wrong:

var encrypted = CryptoJS.AES.encrypt(password, keyBase64,
{
    keySize: 128 / 8,
    iv: iv,
    mode: CryptoJS.mode.CFB,
    padding: CryptoJS.pad.NoPadding
});

Solution

  • The Cipher Feedback (CFB) mode is a family of block cipher modes with a segment size parameter. Mcrypt only supports CFB8 whereas CryptoJS only supports CFB128. They are incompatible.

    I've implemented CFBb in CryptoJS which also supports 8-bit segments, but it is only tested for CryptoJS 3.1.2 and not the CryptoJS 2 version which is available through NPM.