Created
January 2, 2013 19:16
-
-
Save anonymous/4437043 to your computer and use it in GitHub Desktop.
sha1 possible implementation
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
// Sha-1 operations. | |
public static String sha1(String input) { | |
MessageDigest mdigest; | |
String retVal = null; | |
try { | |
mdigest = MessageDigest.getInstance("SHA1"); | |
byte[] rawDigest = mdigest.digest(input.getBytes()); | |
StringBuffer sb = new StringBuffer(); | |
for (byte b : rawDigest) { | |
sb.append(String.format("%02X", b)); | |
} | |
retVal = sb.toString(); | |
} catch (NoSuchAlgorithmException e) { | |
System.err.println("Error occurred in running sha1: " | |
+ e.getMessage()); | |
} | |
return retVal; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment