Java SHA256 sha256(String message)

Here you can find the source of sha256(String message)

Description

sha

License

Open Source License

Declaration

public static byte[] sha256(String message) throws NoSuchAlgorithmException 

Method Source Code

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

import java.nio.charset.Charset;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class Main {
    private static final String ERROR_NULL_INPUT = "Input can't be null.";
    private static final String UTF8 = "UTF-8";
    private static final String SHA256 = "SHA-256";

    public static byte[] sha256(String message) throws NoSuchAlgorithmException {
        MessageDigest md = MessageDigest.getInstance(SHA256);
        return md.digest(stringToBytes(message));
    }//  w w w  .  j a  v  a  2s . c  o  m

    public static byte[] stringToBytes(String input) {

        if (input == null) {
            throw new IllegalArgumentException(ERROR_NULL_INPUT);
        }

        return input.getBytes(Charset.forName(UTF8));
    }
}

Related

  1. sha256(String base)
  2. sha256(String base)
  3. sha256(String data)
  4. sha256(String Input)
  5. SHA256(String input)
  6. sha256(String password, String salt)
  7. sha256(String plainText)
  8. sha256(String raw)
  9. sha256(String s)