I have some String I'd like to hash using the SHA-256 way. I looked a bit on the internet and to my great surprise, I can't find a simple way to do so.
I'm aware of the MessageDigest
class wich seems to provide everything I need except one thing : a method like this : String hash256(String txt)
I also know there are ways to do so (for instance : here) but I'm reluctant to writing more than one line for something probably already existing. Do you guys know if such a thing exists ?
EDIT : it looks like I wasn't clear enough. Is there an existing method equivalent to the following code in JDK ?
public String hash256(String txt){
MessageDigest sha = MessageDigest.getInstance("SHA-256");
sha.update(txt.getBytes());
byte[] digest = sha.digest();
return bytesToString(digest);
}