Last active
December 24, 2015 14:59
-
-
Save chris-piekarski/6816085 to your computer and use it in GitHub Desktop.
Hash a String using SHA-1 and return hash as String
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static String getSha1Hash(String value) { | |
MessageDigest digester = null; | |
String sha1Value = null; | |
try { | |
digester = MessageDigest.getInstance("SHA-1"); | |
digester.update(value.getBytes("UTF-8"), 0, value.length()); | |
byte[] sha1hash = digester.digest(); | |
StringBuilder sb = new StringBuilder(); | |
for( byte b : sha1hash ) | |
{ | |
sb.append( String.format("%02X", b) ); | |
} | |
sha1Value = sb.toString(); | |
} | |
catch (Exception e) { | |
Log.e(TAG, "Exception: "+e); | |
throw new RuntimeException(e); | |
} | |
return sha1Value; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment