Java SHA256 sha256Hash()

Here you can find the source of sha256Hash()

Description

sha Hash

License

Open Source License

Declaration

static public MessageDigest sha256Hash() throws NoSuchAlgorithmException 

Method Source Code

//package com.java2s;
/*//from w w w.  j  a va2s.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 MessageDigest sha256Hash() throws NoSuchAlgorithmException {
        return MessageDigest.getInstance("SHA-256");
    }

    static public byte[] sha256Hash(byte data[]) {
        try {
            return hash(data, sha256Hash());
        } 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. sha256digest(@Nonnull byte[] data)
  2. sha256Digest(byte[] bytes)
  3. sha256Digest(final InputStream data)
  4. sha256Encode(String message)
  5. sha256encrypt(String phrase)
  6. sha256Hash(byte[] data)
  7. sha256Hash(File file)
  8. sha256Hash(final String tohash)
  9. sha256HashHex(String data)