SHA-1 Hash Function

1 vote · 0 comments

SHA-1 Hash function

160-bit http://en.wikipedia.org/wiki/SHA-1 Code pieced together from stackoverflow.com

raw ·
copy
· download
public String sha1(String s) { MessageDigest digest = null; try { digest = MessageDigest.getInstance("SHA-1"); } catch (NoSuchAlgorithmException e) { // TODO Auto-generated catch block e.printStackTrace(); } digest.reset(); byte[] data = digest.digest(s.getBytes()); return String.format("%0" + (data.length*2) + "X", new BigInteger(1, data)); }

Be the first to comment

Sign in with OpenID