Java tutorial
//package com.java2s; import java.math.BigInteger; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; public class Main { public static String encodeSHAString(String str) { return encode(str, "SHA"); } 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); int dstrCount = 32 - dstr.length(); for (int i = 0; i < dstrCount; i++) { dstr = "0" + dstr; } } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } return dstr; } }