Search code examples
javaencryptionwss4j

Can you ever get partially decrypted data from a decryption algorithm using WSS4J library?


I'm decrypting some data using Java and Apache's most recent WSS4J library with 128-bit AES decryption.

I setup the the cipher which appears to be correct with the right padding, decryption algorithm, and cipher block mode.

I then make a call to doFinal() on the encrypted data bytes and it successfully returns a value.

My question is would it ever return a value that is only partially decrypted?

For example, let's say the first 16 bytes are still jumbled up after decryption, but the remainder of the data returned has been successfully decrypted, and is human-readable with the expected data there.

Would this mean that there could be an issue with my decryption process? Or would it not even be able to return a value from the doFinal() step if something was even slightly off with the decryption setup?

If I get a value returned from doFinal() would that mean that 100% the data returned is the original data before it was encrypted?

I'm decrypting data from a web service call and the owners of the web service are claiming that I must be doing something wrong during my decryption process and that they are sending the data correctly.


Solution

  • Yes, that is possible. A prime example would be if you try to decrypt something in CBC mode with the wrong Initialization Vector (IV). That would result in the first part decrypted to be invalid.

    This is due to how the IV is XORed to the first block of plaintext in CBC mode.