-
-
Save hungbang/c80c7ddfb521c841e18e159f4ba28c15 to your computer and use it in GitHub Desktop.
Hashing a String with SHA1 in Java
This file contains hidden or 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.io.*; | |
| import java.util.logging.*; | |
| import javax.xml.bind.DatatypeConverter; | |
| /** | |
| * Hashing with SHA1 | |
| * | |
| * @param input String to hash | |
| * @return String hashed | |
| */ | |
| public String sha1(String input) { | |
| String sha1 = null; | |
| try { | |
| MessageDigest msdDigest = MessageDigest.getInstance("SHA-1"); | |
| msdDigest.update(input.getBytes("UTF-8"), 0, input.length()); | |
| sha1 = DatatypeConverter.printHexBinary(msdDigest.digest()); | |
| } catch (UnsupportedEncodingException | NoSuchAlgorithmException e) { | |
| Logger.getLogger(Encriptacion.class.getName()).log(Level.SEVERE, null, e); | |
| } | |
| return sha1; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment