Java SHA256 SHA256(byte[] P)

Here you can find the source of SHA256(byte[] P)

Description

SHA

License

Open Source License

Declaration

public static String SHA256(byte[] P) 

Method Source Code


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

import java.security.MessageDigest;

public class Main {
    public static String SHA256(byte[] P) {
        try {// w w w. j av a  2  s  .  c o  m
            MessageDigest SIG = MessageDigest.getInstance("SHA-256");
            SIG.update(P, 0, P.length);

            byte D[] = SIG.digest();

            return getHexString(D);

        } catch (java.security.NoSuchAlgorithmException e) {
            throw new RuntimeException(e);

        }

    }

    public static String SHA256(String s) {
        return SHA256(s.getBytes());
    }

    public static String getHexString(byte[] data) {
        StringBuilder sb = new StringBuilder();
        for (byte b : data) {
            sb.append(String.format("%02x", b));
        }
        return sb.toString();
    }
}

Related

  1. sha256()
  2. sha256(byte[] bytes)
  3. sha256(byte[] data)
  4. sha256(byte[] data)
  5. SHA256(byte[] input)
  6. SHA256(byte[] src)
  7. SHA256(ByteBuffer buf, int off, int length)
  8. sha256(final InputStream inputStream)
  9. sha256(final String string)