protected static final boolean verifyISO9796(byte[][] key, byte[] data, int off, int len,
                                                 byte[] sig, int sigOff, int sigLen) throws Exception {
        CachingVerifyKey ck = new CachingVerifyKey(key, data, off, len, sig, sigOff, sigLen);
        CachingVerifyKey result = verifyKeysMap.get(ck);

        if (result != null) {
            result.successfulUses += 1;
            return result.result;
        } else {
            if (verifyKeysMap.size() > MAX_CACHE) {
                CachingVerifyKey[] keys = verifyKeysMap.keySet().toArray(new CachingVerifyKey[verifyKeysMap.size()]);
                Arrays.sort(keys, cachingVerifyKeyComparator);
                if (cachingVerifyKeyComparator.compare(keys[0], keys[keys.length - 1]) < 0) {
                    for (int i = 0; i < verifyKeysMap.size() / 5; i++) {
                        verifyKeysMap.remove(keys[i]);
                        keys[i + 1 * verifyKeysMap.size() / 5].successfulUses--;
                        keys[i + 2 * verifyKeysMap.size() / 5].successfulUses--;
                        keys[i + 3 * verifyKeysMap.size() / 5].successfulUses--;
                        keys[i + 4 * verifyKeysMap.size() / 5].successfulUses--;
                    }
                } else {
                    for (int i = 0; i < verifyKeysMap.size() / 5; i++) {
                        verifyKeysMap.remove(keys[keys.length - 1 - i]);
                        keys[keys.length - 1 - i - 1 * verifyKeysMap.size() / 5].successfulUses--;
                        keys[keys.length - 1 - i - 2 * verifyKeysMap.size() / 5].successfulUses--;
                        keys[keys.length - 1 - i - 3 * verifyKeysMap.size() / 5].successfulUses--;
                        keys[keys.length - 1 - i - 4 * verifyKeysMap.size() / 5].successfulUses--;
                    }
                }
            }
        }

        boolean verified = false;

        BigInteger n = new BigInteger(key[0]);
        BigInteger e = new BigInteger(key[1]);

        KeyFactory kFact = null;
        Signature rsaSig = null;

        if (LTPAKeyUtil.isIBMJCEAvailable()) {
            kFact = KeyFactory.getInstance(CRYPTO_ALGORITHM, IBMJCE_NAME);
        } else {
            kFact = KeyFactory.getInstance(CRYPTO_ALGORITHM);
        }
        RSAPublicKeySpec pubKeySpec = new RSAPublicKeySpec(n, e);
        PublicKey pubKey = kFact.generatePublic(pubKeySpec);
        if (LTPAKeyUtil.isIBMJCEAvailable()) {
            rsaSig = Signature.getInstance(SIGNATURE_ALGORITHM, IBMJCE_NAME);
        } else {
            rsaSig = Signature.getInstance(SIGNATURE_ALGORITHM);
        }
        rsaSig.initVerify(pubKey);
        rsaSig.update(data, off, len);
        verified = rsaSig.verify(sig);

        verifyKeysMap.put(ck, ck);
        ck.result = verified;
        ck.successfulUses = 0;

        return verified;
    }
protected static final boolean verifyISO9796 ( byte [ ] [ ] key , byte [ ] data , int off , int len , byte [ ] sig , int sigOff , int sigLen ) throws Exception { CachingVerifyKey ck = new CachingVerifyKey ( key , data , off , len , sig , sigOff , sigLen ) ; CachingVerifyKey result = verifyKeysMap . get ( ck ) ; if ( result != null ) { result . successfulUses += 1 ; return result . result ; } else { if ( verifyKeysMap . size ( ) > MAX_CACHE ) { CachingVerifyKey [ ] keys = verifyKeysMap . keySet ( ) . toArray ( new CachingVerifyKey [ verifyKeysMap . size ( ) ] ) ; Arrays . sort ( keys , cachingVerifyKeyComparator ) ; if ( cachingVerifyKeyComparator . compare ( keys [ 0 ] , keys [ keys . length - 1 ] ) < 0 ) { for ( int i = 0 ; i < verifyKeysMap . size ( ) / 5 ; i ++ ) { verifyKeysMap . remove ( keys [ i ] ) ; keys [ i + 1 * verifyKeysMap . size ( ) / 5 ] . successfulUses -- ; keys [ i + 2 * verifyKeysMap . size ( ) / 5 ] . successfulUses -- ; keys [ i + 3 * verifyKeysMap . size ( ) / 5 ] . successfulUses -- ; keys [ i + 4 * verifyKeysMap . size ( ) / 5 ] . successfulUses -- ; } } else { for ( int i = 0 ; i < verifyKeysMap . size ( ) / 5 ; i ++ ) { verifyKeysMap . remove ( keys [ keys . length - 1 - i ] ) ; keys [ keys . length - 1 - i - 1 * verifyKeysMap . size ( ) / 5 ] . successfulUses -- ; keys [ keys . length - 1 - i - 2 * verifyKeysMap . size ( ) / 5 ] . successfulUses -- ; keys [ keys . length - 1 - i - 3 * verifyKeysMap . size ( ) / 5 ] . successfulUses -- ; keys [ keys . length - 1 - i - 4 * verifyKeysMap . size ( ) / 5 ] . successfulUses -- ; } } } } boolean verified = false ; BigInteger n = new BigInteger ( key [ 0 ] ) ; BigInteger e = new BigInteger ( key [ 1 ] ) ; KeyFactory kFact = null ; Signature rsaSig = null ; if ( LTPAKeyUtil . isIBMJCEAvailable ( ) ) { kFact = KeyFactory . getInstance ( CRYPTO_ALGORITHM , IBMJCE_NAME ) ; } else { kFact = KeyFactory . getInstance ( CRYPTO_ALGORITHM ) ; } RSAPublicKeySpec pubKeySpec = new RSAPublicKeySpec ( n , e ) ; PublicKey pubKey = kFact . generatePublic ( pubKeySpec ) ; if ( LTPAKeyUtil . isIBMJCEAvailable ( ) ) { rsaSig = Signature . getInstance ( SIGNATURE_ALGORITHM , IBMJCE_NAME ) ; } else { rsaSig = Signature . getInstance ( SIGNATURE_ALGORITHM ) ; } rsaSig . initVerify ( pubKey ) ; rsaSig . update ( data , off , len ) ; verified = rsaSig . verify ( sig ) ; verifyKeysMap . put ( ck , ck ) ; ck . result = verified ; ck . successfulUses = 0 ; return verified ; }
Verify if the signature of the data is correct.

@param key The key used to verify the data
@param data The byte representation of the data
@param off The offset of the data
@param len The length of the data
@param sig The signature of the data
@param off The offset of the signature
@param len The length of the signature
@return True if the signature of the data is correct