| 239 | /// algorithm must match the token's `alg` header (RS256/384/512 or |
| 240 | /// ES256/384/512). |
| 241 | public boolean verify(PublicKey publicKey) { |
| 242 | String alg = getAlgorithm(); |
| 243 | if (NONE.equals(alg)) { |
| 244 | return verifyAllowNoneAlgorithm && (signature == null || signature.length == 0); |
| 245 | } |
| 246 | String sigAlg = signatureAlgorithmFor(alg); |
| 247 | byte[] data; |
| 248 | try { |
| 249 | data = signingInput.getBytes("UTF-8"); |
| 250 | } catch (UnsupportedEncodingException e) { |
| 251 | throw new CryptoException("UTF-8 not supported", e); |
| 252 | } |
| 253 | byte[] sig = signature; |
| 254 | if (alg.startsWith("ES")) { |
| 255 | sig = joseToDerEcdsa(sig, ecdsaCoordinateLength(alg)); |
| 256 | } |
| 257 | return Signature.verify(sigAlg, publicKey, data, sig); |
| 258 | } |
| 259 | |
| 260 | // ================================================================ |
| 261 | // accessors |