Java SHA256 sha256(String raw)

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

Description

sha

License

Open Source License

Declaration

public static String sha256(String raw) 

Method Source Code


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

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

public class Main {
    public static String sha256(String raw) {
        return digest(raw, "SHA-256");
    }// w w w . ja va  2s.  com

    private static String digest(String raw, String algorithm) {
        if (raw == null || "".equals(raw))
            return "";
        MessageDigest md;
        try {
            md = MessageDigest.getInstance(algorithm);
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException(e);
        }
        md.update(raw.getBytes());
        StringBuilder sb = new StringBuilder();
        for (byte b : md.digest()) {
            String hex = String.format("%02x", b);
            sb.append(hex);
        }
        return sb.toString();
    }
}

Related

  1. sha256(String Input)
  2. SHA256(String input)
  3. sha256(String message)
  4. sha256(String password, String salt)
  5. sha256(String plainText)
  6. sha256(String s)
  7. sha256(String src)
  8. sha256(String srcStr)
  9. sha256(String str)