public static String calculateSHAHash ( String s ) throws NoSuchAlgorithmException , UnsupportedEncodingException { MessageDigest md = MessageDigest . getInstance ( "SHA-256" ) ; md . update ( s . getBytes ( "UTF-8" ) ) ; byte [ ] digest = md . digest ( ) ; StringBuilder hashVal = new StringBuilder ( ) ; for ( byte b : digest ) { hashVal . append ( String . format ( "%02x" , b ) ) ; } return hashVal . toString ( ) ; }
Hashes a string using SHA - 256 .