Skip to content

Instantly share code, notes, and snippets.

@santiihoyos
Last active March 13, 2016 17:54
Show Gist options
  • Save santiihoyos/ac66106a3fc14156ed77 to your computer and use it in GitHub Desktop.
Save santiihoyos/ac66106a3fc14156ed77 to your computer and use it in GitHub Desktop.
Get Hash of SHA1
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class SHA1 {
private MessageDigest md;
private byte[] buffer, digest;
private String hash = "";
public String getHash(String message) throws NoSuchAlgorithmException {
buffer = message.getBytes();
md = MessageDigest.getInstance("SHA1");
md.update(buffer);
digest = md.digest();
for (byte aux : digest) {
int b = aux & 0xff;
if (Integer.toHexString(b).length() == 1) {
hash += "0";
}
hash += Integer.toHexString(b);
}
return hash;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment