有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

节点。Nodejs中的js-Java密码

我得到了将这个Java解密方法转换成NodeJ的任务,但我并不真正理解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);

共 (0) 个答案