I'm trying to hash some passwords with SHA2.
Where can I get a snippet of java code for make that?
I have seen that post but I have something missing: SHA2 password storage with Java
Mac mac = Mac.getInstance("HmacSha256");
SecretKeySpec secret = new SecretKeySpec(key.getBytes(), "HmacSha256");
mac.init(secret);
byte[] shaDigest = mac.doFinal(phrase.getBytes());
String hash = "";
for(byte b:shaDigest) {
hash += String.format("%02x",b);
}
The phrase is the String I want encode right? And what is the key (line 2)
Thanks in advance
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With