Here you can find the source of sha1(String src)
Parameter | Description |
---|---|
src | a string to digest |
public static String sha1(String src)
//package com.java2s; //License from project: Apache License import java.math.BigInteger; import java.nio.charset.StandardCharsets; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; public class Main { private static MessageDigest md; /**/*from www.j a v a 2 s.com*/ * Calculates the SHA-1 digest and returns the value as a 40 character hex * string. * * @param src * a string to digest * @return SHA-1 digest as a hex string */ public static String sha1(String src) { try { md = MessageDigest.getInstance("SHA"); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } md.update(src.getBytes(StandardCharsets.UTF_8)); return String.format("%040x", new BigInteger(1, md.digest())); } }