| 307 | } |
| 308 | |
| 309 | private static byte[] computeHmac(String algorithm, byte[] secret, String signingInput) { |
| 310 | String hashAlg; |
| 311 | if (HS256.equals(algorithm)) { |
| 312 | hashAlg = Hash.SHA256; |
| 313 | } else if (HS384.equals(algorithm)) { |
| 314 | hashAlg = Hash.SHA384; |
| 315 | } else if (HS512.equals(algorithm)) { |
| 316 | hashAlg = Hash.SHA512; |
| 317 | } else { |
| 318 | throw new CryptoException("unsupported HMAC algorithm: " + algorithm); |
| 319 | } |
| 320 | try { |
| 321 | return Hmac.create(hashAlg, secret).doFinal(signingInput.getBytes("UTF-8")); |
| 322 | } catch (UnsupportedEncodingException e) { |
| 323 | throw new CryptoException("UTF-8 not supported", e); |
| 324 | } |
| 325 | } |
| 326 | |
| 327 | private static String signatureAlgorithmFor(String jwtAlg) { |
| 328 | if (RS256.equals(jwtAlg)) { |