Implementing CryptoJS in Ionic using CFB mode


I want to implement CryptoJS in ionic 3 and i have installed the CryptoJS plugin by running this command npm install crypto-js --save
I have used the import 'import * as CryptoJS from ‘crypto-js’;'
Iam able to encrypt using a secretPhrase using the command
encryptedData =CryptoJS.AES.encrypt(“Text to encrypt”, “sexcretPhrase”);

the problem comes when i want to use CFB mode during encryption so that i can decrypt with Pycrypto at the backend, This is my code:
var KEY = ‘This is a key123’;
var IV = ‘This is an IV456’;
var MODE = new CryptoJS.mode.CFB(CryptoJS.pad.ZeroPadding);
var plaintext = ‘The answer is no’;
var input_bytes = CryptoJS.charenc.UTF8.stringToBytes(plaintext);
var key = CryptoJS.charenc.UTF8.stringToBytes(KEY);
var options = {iv: CryptoJS.charenc.UTF8.stringToBytes(IV), asBytes: true, mode: MODE};
var encrypted = CryptoJS.AES.encrypt(input_bytes, key, options);
var encrypted_hex = CryptoJS.util.bytesToHex(encrypted);
console.log(encrypted_hex); // this is the value you send over the wire

when i run it throws this error

Iam i missing something?


I believe you missed searching this forum for previous postings? :slight_smile:



Thanks for your response but this does not solve my problem. I want to encrypt using CFB mode such that i will be able to decrypt using Pycrypto . The method above just encrypts using a key only, the mode is not taken care of.


ok. sorry. don’t have a solution for you without searching myself