Code example for InvalidKeyException

0
        PublicKey   publicKey)
        throws InvalidKeyException 
    { 
        if (!(publicKey instanceof RSAPublicKey))
        { 
            throw new InvalidKeyException("Supplied key (" + getType(publicKey) + ") is not a RSAPublicKey instance");
        } 
 
        CipherParameters    param = RSAUtil.generatePublicKeyParameter((RSAPublicKey)publicKey);
 
        digest.reset();
        cipher.init(false, param);
    } 
 
    protected void engineInitSign( 
        PrivateKey  privateKey)
        throws InvalidKeyException 
    { 
        if (!(privateKey instanceof RSAPrivateKey))
        { 
            throw new InvalidKeyException("Supplied key (" + getType(privateKey) + ") is not a RSAPrivateKey instance");