Java tutorial
//package com.java2s; import android.util.Base64; import javax.crypto.Mac; import javax.crypto.spec.SecretKeySpec; public class Main { /** * #### * Methods to convert params to URL encoded form */ private static final String UTF_8 = "UTF-8"; private static final String HMAC_SHA1 = "HmacSHA1"; private static final String EMPTY_STRING = ""; private static final String CARRIAGE_RETURN = "\r\n"; public static String doSignWithSHA1(String toSign, String keyString) throws Exception { SecretKeySpec key = new SecretKeySpec((keyString).getBytes(UTF_8), HMAC_SHA1); Mac mac = Mac.getInstance(HMAC_SHA1); mac.init(key); byte[] bytes = mac.doFinal(toSign.getBytes(UTF_8)); return Base64.encodeToString(bytes, Base64.CRLF).replace(CARRIAGE_RETURN, EMPTY_STRING); } }