Skip to content

Instantly share code, notes, and snippets.

@t0k4rt
Forked from tistaharahap/gist:1202974
Last active September 29, 2015 23:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save t0k4rt/ee26f3fb923fb5d56fb6 to your computer and use it in GitHub Desktop.
Save t0k4rt/ee26f3fb923fb5d56fb6 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 {
Mac mac = Mac.getInstance("HmacSHA1");
SecretKeySpec secret = new SecretKeySpec(keyString.getBytes("UTF-8"), mac.getAlgorithm());
mac.init(secret);
byte[] digest = mac.doFinal(s.getBytes());
String retVal = Base64.encodeBase64String(digest);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment