List of utility methods to do HMAC
byte[] | hmacSha256(String keyHex, String stringData) hmac Sha byte[] keyBytes = hex_to_bytes(keyHex); byte[] data = string_to_bytes(stringData); Mac sha256_HMAC = Mac.getInstance("HmacSHA256"); SecretKeySpec secret_key = new SecretKeySpec(keyBytes, "HmacSHA256"); sha256_HMAC.init(secret_key); return sha256_HMAC.doFinal(data); |
String | hmacsha256Representation(String data, String pusherApplicationSecret) Returns a HMAC/SHA256 representation of the given string try { final SecretKeySpec signingKey = new SecretKeySpec(pusherApplicationSecret.getBytes(), "HmacSHA256"); final Mac mac = Mac.getInstance("HmacSHA256"); mac.init(signingKey); byte[] digest = mac.doFinal(data.getBytes("UTF-8")); digest = mac.doFinal(data.getBytes()); BigInteger bigInteger = new BigInteger(1, digest); return String.format("%0" + (digest.length << 1) + "x", bigInteger); ... |
byte[] | hmacSha512(byte[] key, byte[] message) hmac Sha Mac mac = Mac.getInstance(HMAC_SHA512); mac.init(new SecretKeySpec(key, HMAC_SHA512)); return mac.doFinal(message); |
String | hmacSign(String aValue, String aKey) hmac Sign byte k_ipad[] = new byte[64]; byte k_opad[] = new byte[64]; byte keyb[]; byte value[]; try { keyb = aKey.getBytes("UTF-8"); value = aValue.getBytes("UTF-8"); } catch (UnsupportedEncodingException e) { ... |
String | hmacSign(String skey, String data) hmac Sign SecretKeySpec key = new SecretKeySpec(skey.getBytes(), "HmacSHA1"); Mac mac = Mac.getInstance("HmacSHA1"); mac.init(key); byte[] raw = mac.doFinal(data.getBytes()); return bytesToHex(raw); |