List of utility methods to do HmacSHA256 Create
String | getHmacSha256Base64(String key, String data) get Hmac Sha Base final String encryptionAlgorithm = "HmacSHA256"; SecretKey secretKey = new SecretKeySpec(data.getBytes(), encryptionAlgorithm); Mac messageAuthenticationCode = Mac .getInstance(encryptionAlgorithm); messageAuthenticationCode.init(secretKey); messageAuthenticationCode.update(key.getBytes()); byte[] digest = messageAuthenticationCode.doFinal(); ... |
byte[] | encryptHMAC(String data, String secret) encrypt HMAC byte[] bytes = null; try { SecretKey secretKey = new SecretKeySpec( secret.getBytes("UTF-8"), "HmacMD5"); Mac mac = Mac.getInstance(secretKey.getAlgorithm()); mac.init(secretKey); bytes = mac.doFinal(data.getBytes("UTF-8")); } catch (GeneralSecurityException gse) { ... |
String | hmacSha1(String str, String keyString) hmac Sha final byte[] keyBytes = keyString.getBytes(); try { SecretKey key = new SecretKeySpec(keyBytes, "HmacSHA1"); Mac mac = Mac.getInstance("HmacSHA1"); mac.init(key); final byte[] sbs = str.getBytes(); byte[] result = mac.doFinal(sbs); return toHex(result); ... |