public byte [ ] decrypt ( byte [ ] text , PrivateKey key ) throws MangooEncryptionException { Objects . requireNonNull ( text , Required . ENCRYPTED_TEXT . toString ( ) ) ; Objects . requireNonNull ( text , Required . PRIVATE_KEY . toString ( ) ) ; byte [ ] decrypt = null ; try { Cipher cipher = Cipher . getInstance ( ENCRYPTION ) ; cipher . init ( Cipher . DECRYPT_MODE , key ) ; decrypt = cipher . doFinal ( text ) ; } catch ( InvalidKeyException | NoSuchAlgorithmException | NoSuchPaddingException | IllegalBlockSizeException | BadPaddingException e ) { throw new MangooEncryptionException ( "Failed to decrypt encrypted text with private key" , e ) ; } return decrypt ; }
Decrypt text using private key