public String encrypt ( String text , PublicKey key ) throws MangooEncryptionException { Objects . requireNonNull ( text , Required . PLAIN_TEXT . toString ( ) ) ; Objects . requireNonNull ( text , Required . PUBLIC_KEY . toString ( ) ) ; String encrypt = null ; try { byte [ ] cipherText = encrypt ( text . getBytes ( StandardCharsets . UTF_8 ) , key ) ; encrypt = encodeBase64 ( cipherText ) ; } catch ( MangooEncryptionException e ) { throw new MangooEncryptionException ( "Failed to encrypt clear text with public key" , e ) ; } return encrypt ; }
Encrypt a text using public key . The result is encoded to Base64 .