Java SHA1 sha1HashHex(String data)

Here you can find the source of sha1HashHex(String data)

Description

sha Hash Hex

License

Open Source License

Declaration

static public String sha1HashHex(String data) 

Method Source Code

//package com.java2s;
/*//from  w w w  .j  a v a 2s . co  m
 * Copyright 2014-2017.
 * Distributed under the terms of the GPLv3 License.
 *
 * Authors:
 *      Clemens Zeidler <czei002@aucklanduni.ac.nz>
 */

import java.security.*;

public class Main {
    static public String sha1HashHex(byte data[]) {
        return toHex(sha1Hash(data));
    }

    static public String sha1HashHex(String data) {
        return sha1HashHex(data.getBytes());
    }

    public static String toHex(byte[] bytes) {
        StringBuffer stringBuffer = new StringBuffer();
        for (int i = 0; i < bytes.length; i++)
            stringBuffer.append(String.format("%02X", bytes[i]));

        return stringBuffer.toString().toLowerCase();
    }

    static public MessageDigest sha1Hash() throws NoSuchAlgorithmException {
        return MessageDigest.getInstance("SHA-1");
    }

    static public byte[] sha1Hash(byte data[]) {
        try {
            return hash(data, sha1Hash());
        } catch (Exception e) {
            System.out.println(e.getMessage());
            return null;
        }
    }

    static public byte[] hash(byte[] data, MessageDigest messageDigest) {
        messageDigest.reset();
        messageDigest.update(data);
        return messageDigest.digest();
    }
}

Related

  1. sha1Hash(String s)
  2. sha1Hash(String source)
  3. sha1Hash(String text)
  4. sha1Hash(String tohash)
  5. sha1Hash(String toHash)
  6. sha1HashInt(String text)
  7. sha1Hex(byte[] bytes)
  8. sha1Hex(String data)
  9. sha1hex(String source)