@ Override public byte [ ] decrypt ( EncryptedData dataToDecrypt , KeyParameter aesKey ) throws KeyCrypterException { checkNotNull ( dataToDecrypt ) ; checkNotNull ( aesKey ) ; try { ParametersWithIV keyWithIv = new ParametersWithIV ( new KeyParameter ( aesKey . getKey ( ) ) , dataToDecrypt . initialisationVector ) ; // Decrypt the message. BufferedBlockCipher cipher = new PaddedBufferedBlockCipher ( new CBCBlockCipher ( new AESEngine ( ) ) ) ; cipher . init ( false , keyWithIv ) ; byte [ ] cipherBytes = dataToDecrypt . encryptedBytes ; byte [ ] decryptedBytes = new byte [ cipher . getOutputSize ( cipherBytes . length ) ] ; final int length1 = cipher . processBytes ( cipherBytes , 0 , cipherBytes . length , decryptedBytes , 0 ) ; final int length2 = cipher . doFinal ( decryptedBytes , length1 ) ; return Arrays . copyOf ( decryptedBytes , length1 + length2 ) ; } catch ( InvalidCipherTextException e ) { throw new KeyCrypterException . InvalidCipherText ( "Could not decrypt bytes" , e ) ; } catch ( RuntimeException e ) { throw new KeyCrypterException ( "Could not decrypt bytes" , e ) ; } }
Decrypt bytes previously encrypted with this class .