Guest User

Untitled

a guest
Feb 21st, 2018
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. import javax.crypto.Mac;
  2. import javax.crypto.spec.SecretKeySpec;
  3.  
  4. public static String someHashMethod(String data, String hash) {
  5. byte[] hashBytes = hash.getBytes();
  6. SecretKeySpec signKey = new SecretKeySpec(hashBytes, "HmacSHA1");
  7.  
  8. Mac mac = Mac.getInstance("HmacSHA1");
  9. mac.init(signKey);
  10.  
  11. byte[] rawHmac = mac.doFinal(data.getBytes());
  12.  
  13. BigInteger number = new BigInteger(1, rawHmac);
  14. String returnHash = number.toString(16);
  15.  
  16. if (returnHash.length() == 39) {
  17. returnHash = "0" + returnHash;
  18. }
  19. return returnHash;
  20. }
Add Comment
Please, Sign In to add comment