Last active
March 13, 2016 17:54
-
-
Save santiihoyos/ac66106a3fc14156ed77 to your computer and use it in GitHub Desktop.
Get Hash of SHA1
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
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