Java SHA256 sha256(String base)

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

Description

sha

License

Open Source License

Declaration

public static String sha256(String base) throws Exception 

Method Source Code


//package com.java2s;
import java.security.MessageDigest;

public class Main {
    public static String sha256(String base) throws Exception {

        MessageDigest digest = MessageDigest.getInstance("SHA-256");
        byte[] hash = digest.digest(base.getBytes());
        StringBuffer hexString = new StringBuffer();

        for (int i = 0; i < hash.length; i++) {
            String hex = Integer.toHexString(0xff & hash[i]);
            if (hex.length() == 1) {
                hexString.append('0');
            }/*from  w w w  .  j a v  a2  s  .  c  o  m*/
            hexString.append(hex);
        }

        return hexString.toString();
    }
}

Related

  1. SHA256(ByteBuffer buf, int off, int length)
  2. sha256(final InputStream inputStream)
  3. sha256(final String string)
  4. sha256(InputStream data)
  5. sha256(String base)
  6. sha256(String data)
  7. sha256(String Input)
  8. SHA256(String input)
  9. sha256(String message)