Code example for X509EncodedKeySpec

0
        return cipher;
    } 
 
    public static PublicKey getPubkey(EncryptionRequest request) throws GeneralSecurityException
    { 
        return KeyFactory.getInstance( "RSA" ).generatePublic( new X509EncodedKeySpec( request.getPublicKey() ) );
    } 
 
    public static byte[] encrypt(Key key, byte[] b) throws GeneralSecurityException
    { 
        Cipher hasher = Cipher.getInstance( "RSA" );
        hasher.init( Cipher.ENCRYPT_MODE, key );
        return hasher.doFinal( b );
    } 
} 
Contextual code suggestions in your IDE  Get Codota for Java