Here you can find the source of SHAsum(byte[] input)
Parameter | Description |
---|---|
input | array of bytes. |
public static String SHAsum(byte[] input)
//package com.java2s; //License from project: Open Source License import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.Formatter; public class Main { /**/*from w ww.j av a 2s .c om*/ * Creates the SHA1 hash for a given array of bytes. * @param input array of bytes. * @return String representation of SHA1 hash. */ public static String SHAsum(byte[] input) { MessageDigest md; try { md = MessageDigest.getInstance("SHA-1"); return byteArray2Hex(md.digest(input)); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } return null; } /** * Takes an array of bytes that should represent a hexadecimal value. * Returns string representation of these values. * @param bytes bytes containing hex symbols. * @return String representation of the byte[] */ private static String byteArray2Hex(final byte[] bytes) { Formatter formatter = new Formatter(); for (byte b : bytes) { formatter.format("%02x", b); } return formatter.toString(); } }