Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.crypto.Mac;
- import javax.crypto.spec.SecretKeySpec;
- public static String someHashMethod(String data, String hash) {
- byte[] hashBytes = hash.getBytes();
- SecretKeySpec signKey = new SecretKeySpec(hashBytes, "HmacSHA1");
- Mac mac = Mac.getInstance("HmacSHA1");
- mac.init(signKey);
- byte[] rawHmac = mac.doFinal(data.getBytes());
- BigInteger number = new BigInteger(1, rawHmac);
- String returnHash = number.toString(16);
- if (returnHash.length() == 39) {
- returnHash = "0" + returnHash;
- }
- return returnHash;
- }
Add Comment
Please, Sign In to add comment