Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save roadlabs/2ed7c2157cfb3dad794d59cfaeef42db to your computer and use it in GitHub Desktop.
Save roadlabs/2ed7c2157cfb3dad794d59cfaeef42db 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) );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment