Java SHA sha(String str)

Here you can find the source of sha(String str)

Description

sha

License

Apache License

Declaration

public static String sha(String str) 

Method Source Code

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

import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class Main {

    public static String sha(String str) {
        return encode(str, "SHA");
    }/* w ww.  j av  a  2 s . c  o  m*/

    private static String encode(String str, String method) {
        MessageDigest md = null;
        String dstr = null;
        try {
            md = MessageDigest.getInstance(method);
            md.update(str.getBytes());
            dstr = new BigInteger(1, md.digest()).toString(16);
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return dstr;
    }
}

Related

  1. sha(byte data[])
  2. sha(byte[] data)
  3. SHA(String s)
  4. sha(String source)
  5. sha(String strPlain)
  6. sha(String text, String encoding)
  7. sha2(String content)
  8. sha2(String input)