Here you can find the source of sha(byte[] data)
byte[]
.
Parameter | Description |
---|---|
data | Data to digest |
public static byte[] sha(byte[] data)
//package com.java2s; //License from project: Open Source License import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; public class Main { public static final String SHA_ALGORITHM = "SHA-1"; /**//from ww w .j a v a2 s.co m * Calculates the SHA digest and returns the symbol as a * <code>byte[]</code>. * * @param data Data to digest * @return SHA digest */ public static byte[] sha(byte[] data) { return getSHA().digest(data); } /** * Calculates the SHA digest and returns the symbol as a * <code>byte[]</code>. * * @param data Data to digest * @return SHA digest */ public static byte[] sha(String data) { return sha(data.getBytes()); } /** * Returns an SHA digest. * * @return An SHA digest creating. * @throws RuntimeException when a {@link java.security.NoSuchAlgorithmException} is caught, */ private static MessageDigest getSHA() { return getMessageDigest(SHA_ALGORITHM); } public static MessageDigest getMessageDigest(String algorithm) { try { return MessageDigest.getInstance(algorithm); } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e.getMessage()); } } }