Skip to content

Instantly share code, notes, and snippets.

@freekman
Created October 28, 2016 07:22
Show Gist options
  • Save freekman/0c3643e3a8d5caf1f8e9558ae916840b to your computer and use it in GitHub Desktop.
Save freekman/0c3643e3a8d5caf1f8e9558ae916840b to your computer and use it in GitHub Desktop.
simple hashing
static String sha1(String input) {
MessageDigest mDigest = null;
try {
mDigest = MessageDigest.getInstance("SHA1");
} catch (NoSuchAlgorithmException e) {
return "";
}
byte[] result = mDigest.digest(input.getBytes());
StringBuffer sb = new StringBuffer();
for (int i = 0; i < result.length; i++) {
sb.append(Integer.toString((result[i] & 0xff) + 0x100, 16).substring(1));
}
return sb.toString();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment