I encrypted a file stream using aes-256-cfb in node.js and read it back in java with AES/CFB8/NoPadding, but this gets corrupted data.
node.js
const aes = crypto.createCipher('aes-256-cfb', '1234567812345678');
aes.setAutoPadding(false);
//const aesd = crypto.createDecipher('aes-256-cfb', password); If i decrypt //with this in node.js, i am able to get back the data. just for a test
var readStream = fs.createReadStream('c:\\test\\orig.txt');
var wstream = fs.createWriteStream('c:\\test\\encrypted.txt');
readStream
.pipe(cipher) // encrypts with aes256
.pipe(wstream)
.on('finish', function () { // finished
console.log('done writing encrypted file');
});
java:
InputStream in = new FileInputStream(new File("c:\\test\\encrypted.txt"));
OutputStream out = new FileOuputStream("c:\\test\\decrypted.txt");
Cipher dcipher = Cipher.getInstance("AES/CFB8/NoPadding");
Key skeySpec = new SecretKeySpec("1234567812345678".getBytes(), "AES");
byte[] ivd = new byte[dcipher.getBlockSize()];
IvParameterSpec ivParams = new IvParameterSpec(ivd);
dcipher.init(Cipher.DECRYPT_MODE, skeySpec, ivParams);
in = new CipherInputStream(in, dcipher);
int numRead = 0;
while ((numRead = in.read(buf)) >= 0) {
out.write(buf, 0, numRead);
}
out.close();
any idea?