Here you can find the source of sha1(final String data)
Parameter | Description |
---|---|
data | A string value |
public static final String sha1(final String data)
//package com.java2s; //License from project: Apache License import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; public class Main { /**//from ww w .j ava2 s. c o m * Returns the SHA-1 of the specified string * * @param data * A string value * @return The SHA-1 value */ public static final String sha1(final String data) { if (null == data) { throw new IllegalArgumentException("null string"); } try { final MessageDigest md = MessageDigest.getInstance("SHA-1"); return toHexString(md.digest(data.getBytes())); } catch (final NoSuchAlgorithmException e) { return null; } } /** * Returns the specified data as hex sequence * * @param data * The data * @return a hex string */ public static String toHexString(byte[] data) { final int n = data.length; final StringBuilder hex = new StringBuilder(); for (int i = 0; i < n; i++) { final byte b = data[i]; hex.append(String.format("%02x", b & 0xff)); } return hex.toString(); } }