Java SHA256 sha256(String text)

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

Description

sha

License

Open Source License

Declaration

public static final String sha256(String text) throws NoSuchAlgorithmException 

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 final String sha256(String text) throws NoSuchAlgorithmException {
        MessageDigest md = MessageDigest.getInstance("SHA-256");
        return toHex(md.digest(text.getBytes()));
    }/*from ww  w. j  a v a  2 s .  co m*/

    public static final String toHex(byte data[]) {
        char[] hex = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', };
        StringBuffer result = new StringBuffer(data.length * 2);

        for (int i = 0; i < data.length; i++) {
            result.append(hex[(data[i] >> 4) & 0x0f]).append(hex[data[i] & 0x0f]);
        }

        return result.toString();
    }
}

Related

  1. sha256(String string)
  2. sha256(String string, String secret)
  3. sha256(String strSrc)
  4. SHA256(String text)
  5. SHA256(String text)
  6. SHA256(String texto)
  7. SHA256Binary(String toHash)
  8. SHA256byte(String input)
  9. sha256digest(@Nonnull byte[] data)