Here you can find the source of shaByte(byte[] in)
Parameter | Description |
---|---|
in | - The array of bytes to be hashed. |
public static byte[] shaByte(byte[] in)
//package com.java2s; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; public class Main { /**/*from w w w .jav a 2s. c om*/ * Returns a byte array representation of the hash * of a string input using the SHA1 hashing algorithm. * * @param in * - The String to be hashed. * @return A byte array of the hashed input. */ public static byte[] shaByte(String in) { return digestByte("SHA", in.getBytes()); } /** * Returns a byte array representation of the hash * of a byte array input using the SHA1 hashing algorithm. * * @param in * - The array of bytes to be hashed. * @return A byte array representation of the input. */ public static byte[] shaByte(byte[] in) { return digestByte("SHA", in); } /** * Returns a digest, in the form of an array of bytes, using various hashing * algorithms. This is a private function used by many of the public * functions within this class. * * @param algorithm * - The hashing algorithm to be used. * @param input * - The array of bytes to be hashed. * @return An array of bytes representing the hash result. */ private static byte[] digestByte(String algorithm, byte[] input) { MessageDigest m; try { m = MessageDigest.getInstance(algorithm); m.update(input, 0, input.length); return m.digest(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } return null; } }