Java Utililty Methods SHA256

List of utility methods to do SHA256

Description

The list of methods to do SHA256 are organized into topic(s).

Method

byte[]sha256(String message)
sha
MessageDigest md = MessageDigest.getInstance(SHA256);
return md.digest(stringToBytes(message));
Stringsha256(String password, String salt)
sha
MessageDigest digest = MessageDigest.getInstance("SHA-256");
digest.reset();
digest.update(salt.getBytes());
byte[] mdbytes = digest.digest(password.getBytes("UTF-8"));
StringBuffer hexString = new StringBuffer();
for (int i = 0; i < mdbytes.length; i++) {
    hexString.append(Integer.toHexString(0xFF & mdbytes[i]));
return hexString.toString();
Stringsha256(String plainText)
sha
String salt = "qwertyuiop!@#$%^&*()zxcvbnm,.";
String sha256Text = null;
if (plainText != null) {
    try {
        MessageDigest sha256 = MessageDigest.getInstance("SHA-256");
        sha256.update(salt.getBytes());
        byte[] byteArray = plainText.getBytes();
        byte[] sha256Bytes = sha256.digest(byteArray);
...
Stringsha256(String raw)
sha
return digest(raw, "SHA-256");
Stringsha256(String s)
sha
MessageDigest md = getMessageDigest("sha-256");
return bytes2HexString(md.digest(s.getBytes(StandardCharsets.UTF_8)));
Stringsha256(String src)
Calculates the SHA-256 digest and returns the value as a 64 character hex string.
try {
    md = MessageDigest.getInstance("SHA-256");
} catch (NoSuchAlgorithmException e) {
    e.printStackTrace();
md.update(src.getBytes(StandardCharsets.UTF_8));
return String.format("%064x", new BigInteger(1, md.digest()));
Stringsha256(String srcStr)
sha
return hash("SHA-256", srcStr);
Stringsha256(String str)
sha
try {
    MessageDigest md = MessageDigest.getInstance("SHA-256");
    md.update(str.getBytes());
    byte[] b = md.digest();
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < b.length; i++) {
        int v = (int) b[i];
        v = v < 0 ? 0x100 + v : v;
...
Stringsha256(String str)
sha
String SHA = "";
try {
    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));
...
byte[]sha256(String string)
sha
MessageDigest digest;
try {
    digest = MessageDigest.getInstance("SHA-256");
} catch (NoSuchAlgorithmException ex) {
    throw new RuntimeException(ex.getMessage(), ex);
return digest.digest(string.getBytes(StandardCharsets.UTF_8));