public String decrypt ( final byte [ ] text , final KeyType keyType ) throws EncryptionException { final Key key = keyType == KeyType . PRIVATE ? privateKey : publicKey ; try { // get an RSA cipher object and print the provider final Cipher cipher = Cipher . getInstance ( ALGORITHM ) ; // decrypt the text using the private key cipher . init ( Cipher . DECRYPT_MODE , key ) ; byte [ ] dectyptedText = cipher . doFinal ( text ) ; return new String ( dectyptedText , DEFAULT_CHARSET ) ; } catch ( NoSuchAlgorithmException | InvalidKeyException | NoSuchPaddingException | BadPaddingException | IllegalBlockSizeException e ) { throw new EncryptionException ( "Unable to decrypt message: " , e ) ; } }
Decrypts the given encrypted message with the specified key type .