Java SHA256 sha256(String str)

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

Description

sha

License

Apache License

Declaration

public static String sha256(String str) 

Method Source Code

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

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

public class Main {
    public static String sha256(String str) {
        String SHA = "";
        try {// w ww  .j  a  va  2s .  com
            MessageDigest sh = MessageDigest.getInstance("SHA-256");
            sh.update(str.getBytes());
            byte byteData[] = sh.digest();
            StringBuffer sb = new StringBuffer();
            for (int i = 0; i < byteData.length; i++) {
                sb.append(Integer
                        .toString((byteData[i] & 0xff) + 0x100, 16)
                        .substring(1));
            }
            SHA = sb.toString();

        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
            SHA = null;
        }
        return SHA;
    }
}

Related

  1. sha256(String raw)
  2. sha256(String s)
  3. sha256(String src)
  4. sha256(String srcStr)
  5. sha256(String str)
  6. sha256(String string)
  7. sha256(String string, String secret)
  8. sha256(String strSrc)
  9. SHA256(String text)