I got the task to convert this Java decryption method into Nodejs, but I don't really understand this Java stuff. I'm especially confused with PBEWithMD5AndDES. Please explain to me, how I can reproduce this decryption in Nodejs.
private void readFile() {
try {
Cipher cipher = getCipher(2, "secret");
DataInputStream dis;
dis = new DataInputStream(new CipherInputStream(someInputStream, cipher));
String field1 = dis.readUTF();
String filed2 = dis.readUTF();
dis.close();
} catch (Exception e) { }
}
private Cipher getCipher(int mode, String password) throws Exception {
Random random = new Random(43287234L);
byte[] salt = new byte[8];
random.nextBytes(salt);
PBEParameterSpec pbeParamSpec = new PBEParameterSpec(salt, 5);
SecretKey pbeKey = SecretKeyFactory.getInstance("PBEWithMD5AndDES").generateSecret(new PBEKeySpec(password.toCharArray()));
Cipher cipher = Cipher.getInstance("PBEWithMD5AndDES");
cipher.init(mode, pbeKey, pbeParamSpec);
return cipher;
}
I assume I have to do stuff similiar to this.
var inputStream = fs.createReadStream("file");
var decipher = crypto.createDecipher("des", "secret", new Buffer("0C9D4AE41E8315FC", "hex"));
inputStream.pipe(decipher).pipe(process.stdout);