Java tutorial
//package com.java2s; import java.math.BigInteger; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; public class Main { private static MessageDigest mSha1Digest; public static String sha1(String s) { if (mSha1Digest == null) { try { mSha1Digest = MessageDigest.getInstance("SHA-1"); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } } byte[] data = mSha1Digest.digest(s.getBytes()); return String.format("%0" + (data.length * 2) + "X", new BigInteger(1, data)); } }