Skip to content

Instantly share code, notes, and snippets.

@tistaharahap
Created September 8, 2011 08:57
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save tistaharahap/1202974 to your computer and use it in GitHub Desktop.
Save tistaharahap/1202974 to your computer and use it in GitHub Desktop.
HMAC-SHA1 Utility for Android
public static String sha1(String s, String keyString) throws
UnsupportedEncodingException, NoSuchAlgorithmException,
InvalidKeyException {
SecretKeySpec key = new SecretKeySpec((keyString).getBytes("UTF-8"), "HmacSHA1");
Mac mac = Mac.getInstance("HmacSHA1");
mac.init(key);
byte[] bytes = mac.doFinal(s.getBytes("UTF-8"));
return new String( Base64.encodeBase64(bytes) );
}
@themaskofwraith
Copy link

Base64.encodeBase64 does not existss in android.

@camiza
Copy link

camiza commented May 23, 2013

replace the line for...
return new String(Base64.encodeToString(bytes, 0));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment