Computes HMAC signature. @param data The data to be signed. @param secretKey The signing secret key. @return The Base64-encoded HMAC signature. @throws java.security.SignatureException when signature generation fails
(String data, String secretKey)
| 261 | * @throws java.security.SignatureException when signature generation fails |
| 262 | */ |
| 263 | private static String calculateHmacSHA1(String data, String secretKey) |
| 264 | throws java.security.SignatureException |
| 265 | { |
| 266 | String Result; |
| 267 | |
| 268 | try |
| 269 | { |
| 270 | Mac mac = Mac.getInstance("HmacSHA1"); // Create an HMAC instance |
| 271 | mac.init(new SecretKeySpec(secretKey.getBytes(), "HmacSHA1")); // Initialize the HMAC instance with the secret key |
| 272 | Result = Base64.getEncoder().encodeToString(mac.doFinal(data.getBytes())); |
| 273 | } |
| 274 | catch (Exception e) |
| 275 | { |
| 276 | throw new SignatureException(e.getMessage()); |
| 277 | } |
| 278 | return Result; |
| 279 | } |
| 280 | |
| 281 | } |