Java SHA256 SHA256(String input)

Here you can find the source of SHA256(String input)

Description

SHA

License

Apache License

Declaration

public static String SHA256(String input) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

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

public class Main {
    public final static String ALGORITHM_SHA256 = "SHA-256";

    public static String SHA256(String input) {
        return toHexString(SHA256byte(input));
    }// w w w.j  a v a2s . co  m

    private static String toHexString(byte[] data) {
        StringBuilder sb = new StringBuilder();
        for (byte b : data) {
            String hex = Integer.toHexString(0xff & b);
            if (hex.length() == 1)
                sb.append('0');
            sb.append(hex);
        }
        return sb.toString();
    }

    private static byte[] SHA256byte(String input) {
        try {
            MessageDigest md = MessageDigest.getInstance(ALGORITHM_SHA256);
            return md.digest(input.getBytes());
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException(e);
        }
    }
}

Related

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