Code example for X509EncodedKeySpec

            throw new InvalidKeySpecException("Must be RSAPublicKey or RSAPrivateKey");
    protected Key engineTranslateKey(Key key) throws InvalidKeyException {
        if (key == null) {
            throw new InvalidKeyException("key == null");
        if (key instanceof RSAPublicKey) {
            RSAPublicKey rsaKey = (RSAPublicKey) key;
            try { 
                return engineGeneratePublic(new RSAPublicKeySpec(rsaKey.getModulus(),
            } catch (InvalidKeySpecException e) {
                throw new InvalidKeyException(e);
        } else if (key instanceof RSAPrivateCrtKey) {
Stop searching for code, let great code find you!  Add Codota to your java IDE