Java SHA1 sha1Hex(byte[] bytes)

Here you can find the source of sha1Hex(byte[] bytes)

Description

sha Hex

License

Open Source License

Declaration

@Deprecated
public static String sha1Hex(byte[] bytes) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.security.MessageDigest;

public class Main {
    /**/*from ww  w . j a  v  a 2 s .co  m*/
    * @deprecated moved to HashFunctions
    */
    @Deprecated
    public static String sha1Hex(byte[] bytes) {
        return toHex(sha1(bytes));
    }

    public static String toHex(byte[] bytes) {
        StringBuffer hexString = new StringBuffer();
        for (int i = 0; i < bytes.length; i++) {
            String hex = Integer.toHexString(0xFF & bytes[i]);
            if (hex.length() == 1) {
                // could use a for loop, but we're only dealing with a single byte
                hexString.append('0');
            }
            hexString.append(hex);
        }
        return hexString.toString();
    }

    /**
     * returns a 20 byte sha1 hash 
     * @param bytes
     * @return
     * @deprecated moved to HashFunctions
     */
    @Deprecated
    public static byte[] sha1(byte[] bytes) {
        try {
            MessageDigest sha = MessageDigest.getInstance("SHA-1");
            byte[] result = sha.digest(bytes);
            return result;
        } catch (Exception x) {

        }
        return null;
    }
}

Related

  1. sha1Hash(String text)
  2. sha1Hash(String tohash)
  3. sha1Hash(String toHash)
  4. sha1HashHex(String data)
  5. sha1HashInt(String text)
  6. sha1Hex(String data)
  7. sha1hex(String source)
  8. sha1Java(String password)
  9. sha1Sum(byte[] ba)