Here you can find the source of sha(String text, String encoding)
public static String sha(String text, String encoding)
//package com.java2s; //License from project: Apache License import java.io.UnsupportedEncodingException; import java.security.MessageDigest; public class Main { public static String sha(String text, String encoding) { return encryptPassword(text, encoding, "sha"); }/*from www . java2 s .c o m*/ private static String encryptPassword(String password, String encoding, String algorithm) { try { byte[] unencodedPassword = password.getBytes(encoding); return encryptPassword(unencodedPassword, algorithm); } catch (UnsupportedEncodingException e) { return null; } } private static String encryptPassword(byte[] unencodedPassword, String algorithm) { MessageDigest md = null; try { md = MessageDigest.getInstance(algorithm); } catch (Exception e) { return null; } md.reset(); md.update(unencodedPassword); byte[] encodedPassword = md.digest(); StringBuilder buf = new StringBuilder(); for (int i = 0; i < encodedPassword.length; i++) { if ((encodedPassword[i] & 0xff) < 0x10) { buf.append("0"); } buf.append(Long.toString(encodedPassword[i] & 0xff, 16)); } return buf.toString(); } }