我得到了将这个 Java 解密方法转换为 Nodejs 的任务,但我不太了解这些 Java 东西。我特别困惑PBEWithMD5AndDES
。请向我解释一下,如何在 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;
}
我想我必须做与此类似的事情。
var inputStream = fs.createReadStream("file");
var decipher = crypto.createDecipher("des", "secret", new Buffer("0C9D4AE41E8315FC", "hex"));
inputStream.pipe(decipher).pipe(process.stdout);