public static byte [ ] decrypt ( byte [ ] text , Key key , String algorithm ) throws DecryptionException { Cipher cipher ; try { LOGGER . trace ( "start decrypting text using {} cipher" , algorithm ) ; cipher = Cipher . getInstance ( algorithm ) ; cipher . init ( Cipher . DECRYPT_MODE , key ) ; LOGGER . trace ( "initialized decryption with key of type {}" , key . getClass ( ) ) ; } catch ( GeneralSecurityException e ) { throw new IllegalArgumentException ( "unable to initialize cipher for algorithm " + algorithm , e ) ; } try { return cipher . doFinal ( text ) ; } catch ( GeneralSecurityException e ) { throw new DecryptionException ( "unable to decrypt data using algorithm " + algorithm , e ) ; } }
Decrypts the given data using the given key using the given algorithm . If you are decrypting data that is supposed to be a string consider that it might be Base64 - encoded .