Java tutorial
//package com.java2s; import android.net.Uri; import android.util.Base64; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; import javax.crypto.Mac; import javax.crypto.spec.SecretKeySpec; public class Main { public static String sign(String paramString1, String paramString2, String paramString3) { if (paramString3 == null) paramString3 = ""; try { SecretKeySpec localSecretKeySpec = new SecretKeySpec( (urlencode(paramString2, "UTF8") + '&' + urlencode(paramString3, "UTF8")).getBytes("UTF8"), "HmacSHA1"); Mac localMac = Mac.getInstance("HmacSHA1"); localMac.init(localSecretKeySpec); String str = urlencode( new String(Base64.encode(localMac.doFinal(paramString1.getBytes("UTF8")), 0), "UTF8"), "UTF8"); return str; } catch (InvalidKeyException localInvalidKeyException) { return ""; } catch (NoSuchAlgorithmException localNoSuchAlgorithmException) { return ""; } catch (UnsupportedEncodingException localUnsupportedEncodingException) { } return ""; } public static String urlencode(String paramString1, String paramString2) { if (paramString1 == null) return ""; try { String str = URLEncoder.encode(paramString1, paramString2); return str; } catch (UnsupportedEncodingException localUnsupportedEncodingException) { throw new RuntimeException(localUnsupportedEncodingException.getMessage(), localUnsupportedEncodingException); } } public static String encode(String paramString) { if (paramString == null) return ""; return Uri.encode(paramString); } }