Here you can find the source of sha1(String s)
Parameter | Description |
---|---|
s | the string |
public static String sha1(String s)
//package com.java2s; //License from project: Open Source License import java.io.UnsupportedEncodingException; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; public class Main { /**/* ww w.j a v a2 s .c o m*/ * Computes the SHA1 sum of the given string. * * @param s the string * @return the SHA1 sum */ public static String sha1(String s) { try { return byteArrayToHexString(MessageDigest.getInstance("SHA").digest(s.getBytes("US-ASCII"))); } catch (NoSuchAlgorithmException | UnsupportedEncodingException nsae) { throw new RuntimeException(nsae); } } /** * Convert a byte array into the corresponding string. * * @param b the byte array to convert * @return the string representation of this byte array */ public static String byteArrayToHexString(byte[] b) { StringBuilder sb = new StringBuilder(b.length * 2); for (byte aB : b) { int j = (aB & 0xff); if (j < 16) { sb.append('0'); } sb.append(Integer.toHexString(j)); } return sb.toString(); } }