Code example for InvalidKeySpecException

0
            } else if (encoded == null) {
                throw new InvalidKeySpecException("Key is not encodable");
            } 
            return (T) new X509EncodedKeySpec(encoded);
        } else { 
            throw new InvalidKeySpecException("Unsupported key type and key spec combination; key="
                    + key.getClass().getName() + ", keySpec=" + keySpec.getName());
        } 
    } 
 
    @Override 
    protected Key engineTranslateKey(Key key) throws InvalidKeyException {
        if (key == null) {
            throw new InvalidKeyException("key == null");
        } 
        if ((key instanceof OpenSSLDSAPublicKey) || (key instanceof OpenSSLDSAPrivateKey)) {
            return key;
        } else if (key instanceof DSAPublicKey) {
            DSAPublicKey dsaKey = (DSAPublicKey) key;
 
            BigInteger y = dsaKey.getY();