Advertisement
Guest User

Untitled

a guest
Oct 28th, 2013
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.42 KB | None | 0 0
  1. public static String sha1(String s, String keyString)
  2.             throws UnsupportedEncodingException, NoSuchAlgorithmException,
  3.             InvalidKeyException {
  4.  
  5.         SecretKeySpec key = new SecretKeySpec((keyString).getBytes("UTF-8"),
  6.                 "HmacSHA1");
  7.         Mac mac = Mac.getInstance("HmacSHA1");
  8.         mac.init(key);
  9.          
  10.  
  11.         byte[] bytes = mac.doFinal(s.getBytes("UTF-8"));
  12.  
  13.         return new String(Base64.encodeToString(bytes, Base64.DEFAULT));
  14.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement