public boolean verifySignature ( final ApnsVerificationKey verificationKey ) throws NoSuchAlgorithmException , InvalidKeyException , SignatureException { if ( ! this . header . getKeyId ( ) . equals ( verificationKey . getKeyId ( ) ) ) { return false ; } if ( ! this . claims . getIssuer ( ) . equals ( verificationKey . getTeamId ( ) ) ) { return false ; } final byte [ ] headerAndClaimsBytes ; final String headerJson = GSON . toJson ( this . header ) ; final String claimsJson = GSON . toJson ( this . claims ) ; final String encodedHeaderAndClaims = encodeUnpaddedBase64UrlString ( headerJson . getBytes ( StandardCharsets . US_ASCII ) ) + ' ' + encodeUnpaddedBase64UrlString ( claimsJson . getBytes ( StandardCharsets . US_ASCII ) ) ; headerAndClaimsBytes = encodedHeaderAndClaims . getBytes ( StandardCharsets . US_ASCII ) ; final Signature signature = Signature . getInstance ( ApnsKey . APNS_SIGNATURE_ALGORITHM ) ; signature . initVerify ( verificationKey ) ; signature . update ( headerAndClaimsBytes ) ; return signature . verify ( this . signatureBytes ) ; }
Verifies the cryptographic signature of this authentication token .