Here you can find the source of generateSHA1Key(String input)
Parameter | Description |
---|---|
input | The string that is to be hashed. |
Parameter | Description |
---|---|
NoSuchAlgorithmException | If the SHA1 hash algorithm is not available on the system. |
public static String generateSHA1Key(String input) throws NoSuchAlgorithmException
//package com.java2s; // it under the terms of the GNU Lesser General Public License as published by import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; public class Main { /**//www . j av a2s . c o m * Generates a SHA1 hash from a string. * @param input The string that is to be hashed. * @return A SHA1 hash * @throws NoSuchAlgorithmException If the SHA1 hash algorithm is not available on the system. */ public static String generateSHA1Key(String input) throws NoSuchAlgorithmException { MessageDigest digest = MessageDigest.getInstance("SHA-1"); String hash; byte[] bytes = digest.digest(input.getBytes()); StringBuilder sb = new StringBuilder(); for (int i = 0; i < bytes.length; i++) { sb.append(Integer.toString((bytes[i] & 0xff) + 0x100, 16).substring(1)); } hash = sb.toString(); return hash; } }