Java SHA sha2(String input)

Here you can find the source of sha2(String input)

Description

sha

License

Apache License

Declaration

static String sha2(String input) throws NoSuchAlgorithmException 

Method Source Code


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

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

public class Main {
    static String sha2(String input) throws NoSuchAlgorithmException {
        MessageDigest mDigest = MessageDigest.getInstance("SHA-256");
        byte[] result = mDigest.digest(input.getBytes());
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < result.length; i++) {
            sb.append(Integer.toString((result[i] & 0xff) + 0x100, 16).substring(1));
        }//from  w ww.j  a v a 2s .c  o m

        return sb.toString();
    }
}

Related

  1. sha(String source)
  2. sha(String str)
  3. sha(String strPlain)
  4. sha(String text, String encoding)
  5. sha2(String content)
  6. sha2(String password)
  7. sha2(String... data)
  8. sha5Encode(byte[] content)
  9. SHA_1(byte[] input)