I have a encryption/decryption functionality in java code and wanted to write the same logic using the crypto node-js library.
What's the equivalent of these Java codes ?
Java code :
String iv = "Some random string";
AlgorithmParameterSpec ivSpec = new IvParameterSpec(iv.getBytes());
What I tried :
const iv = "Some random string"
var ivSpec = new Buffer.from(iv);
Java code :
String key = "Some random key";
SecretKeySpec newKey = new SecretKeySpec(key.getBytes(), "AES");
What I tried :
const key = "Some random key"
var newKey = new Buffer.from(key);
Java code :
String message = "Some message"
Cipher cipher = Cipher.getInstance("AES/CFB/NoPadding");
cipher.init(Cipher.ENCRYPT_MODE, newKey, ivSpec);
byte[] bytes = cipher.doFinal(textBytes.getBytes());
In java code it is using "AES/CFB/NoPadding" and I found equivalent in node js crypto i.e "aes-256-cfb" so I used it.
var crypto = require('crypto');
var cipher = crypto.createCipheriv('aes-256-cfb', newKey, ivSpec);
cipher.update(message, 'utf8');
cipher.final();
Is that correct ? Where I am doin it wrong cause there is no output of cipher.final(). Thanks in advance.