Below code is in Node.js Which library in java I can use for same purpose?
const crypto = require("crypto"); let cryptkey = crypto.createHash('sha256').update('Nixnogen').digest();
Below code is in Node.js Which library in java I can use for same purpose?
const crypto = require("crypto"); let cryptkey = crypto.createHash('sha256').update('Nixnogen').digest();
As explained in this question, you can use:
MessageDigest digest = MessageDigest.getInstance("SHA-256");
byte[] hash = digest.digest("Nitrogen".getBytes(StandardCharsets.UTF_8));
You can refer to javax.crypto.SecretKeyFactory for hashing.
sample code for hashing is as below :
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();