JwtVerifier { public boolean verifyToken(Jwt jwtToken) throws CryptoException { if (jwtToken == null) { throw new NullArgumentException("jwtToken"); } JwtHeaderContent header = jwtToken.getHeaderContent(); if (!this.apiPublicKeyIdentifier.equals(header.getKeyIdentifier()) || !this.accessTokenSigner.getAlgorithm().equals(header.getAlgorithm()) || !JwtHeaderContent.VIRGIL_CONTENT_TYPE.equals(header.getContentType()) || !JwtHeaderContent.JWT_TYPE.equals(header.getType())) { LOGGER.info( "Some of next args mismatches in Jwt header and provided data while instantiating JwtVerifier:\n" + "api public key identifier, algorithm, content type, jwt type"); return false; } byte[] jwtBytes = ConvertionUtils.toBytes(jwtToken.unsigned()); return this.accessTokenSigner.verifyTokenSignature(jwtToken.getSignatureData(), jwtBytes, apiPublicKey); } JwtVerifier(VirgilPublicKey apiPublicKey, String apiPublicKeyIdentifier,
                     VirgilAccessTokenSigner accessTokenSigner); boolean verifyToken(Jwt jwtToken);  }
@Test public void stc_22() throws CryptoException { VirgilAccessTokenSigner signer = new VirgilAccessTokenSigner(); VirgilCrypto crypto = new VirgilCrypto(); String apiPublicKeyId = dataProvider.getString("STC-22.api_key_id"); String apiPublicKeyBase64 = dataProvider.getString("STC-22.api_public_key_base64"); VirgilPublicKey apiPublicKey = crypto .importPublicKey(ConvertionUtils.base64ToBytes(apiPublicKeyBase64)); Jwt token = new Jwt(dataProvider.getString("STC-22.jwt")); JwtVerifier jwtVerifier = new JwtVerifier(apiPublicKey, apiPublicKeyId, signer); assertTrue(jwtVerifier.verifyToken(token)); }
@Test public void verifyToken() throws CryptoException { Jwt token = fake.generateToken(); assertTrue(this.verifier.verifyToken(token)); }