Android SHA256 Hash Create sha256(final String aString)

Here you can find the source of sha256(final String aString)

Description

sha

License

Apache License

Declaration

public static String sha256(final String aString) 

Method Source Code

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

import android.text.TextUtils;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class Main {
    public static String sha256(final String aString) {
        String result = null;/*from   ww  w  .  j  a  va  2 s . co  m*/
        if (TextUtils.isEmpty(aString))
            return result;
        MessageDigest md;
        StringBuffer hexString = new StringBuffer();
        try {
            md = MessageDigest.getInstance("SHA-256");
            md.reset();
            md.update(aString.getBytes());
            byte[] messageDigest = md.digest();
            for (int i = 0; i < messageDigest.length; i++) {
                String hex = Integer.toHexString(0xff & messageDigest[i]);
                if (hex.length() == 1)
                    hexString.append('0');
                hexString.append(hex);
            }
            result = hexString.toString();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return result;
    }
}

Related

  1. sha256(String input)
  2. sha256(String string)
  3. sha256(byte[] data)
  4. sha256(byte[] data, int offset, int length)
  5. sha256(byte[] data1, byte[] data2)
  6. sha256Byte(String in)
  7. sha256Byte(byte[] in)
  8. doubleSha256(byte[] data)
  9. doubleSha256(byte[] data, int offset, int length)