下面的代码在Node.js中 我可以将java中的哪个库用于同一目的?
const crypto = require(“crypto”); let cryptkey = crypto.createHash('sha256')。update('Nixnogen')。digest();
答案 0 :(得分:0)
如this question中所述,您可以使用:
MessageDigest digest = MessageDigest.getInstance("SHA-256");
byte[] hash = digest.digest("Nitrogen".getBytes(StandardCharsets.UTF_8));
答案 1 :(得分:0)
您可以参考javax.crypto.SecretKeyFactory进行散列。
哈希的示例代码如下:
String algorithm = "your algorithm value";//ex:PBKDF2WithHmacSHA512
String salt="randomString";
SecretKeyFactory skf = SecretKeyFactory.getInstance(algorithm);
PBEKeySpec spec = new PBEKeySpec(password, salt.getBytes(), 1000,256);
SecretKey key = skf.generateSecret(spec);
byte[] res = key.getEncoded();
String hashedPassword = res.toString();