Skip to content

Instantly share code, notes, and snippets.

Created January 2, 2013 19:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/4437043 to your computer and use it in GitHub Desktop.
Save anonymous/4437043 to your computer and use it in GitHub Desktop.
sha1 possible implementation
// 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