Hi, I'm trying to migrate all my code to use SecureBlackBox, I've a code that uses a custom library to encode AES 128 CBC, it uses a 16 chars IV, and transfers data to a process made in Java.
Looking in forum find some piece of code on how to encode decode AES, but when I try to set the 16 char IV says that it's invalid IV, there is any prerequisite to set the IV?

We have sample code for symmetric encryption both in {SecureBlackbox}\Samples\{Language}\PKIBlackbox directory and here in the forum. If you don't find one, you are welcome to post your code snippet here for us to check it.

but when I try to set the 16 char IV says that it's invalid IV, there is any prerequisite to set the IV?

The IV should be exactly 16 bytes. A common mistake is assigning a hexadecimal string (having a length of 32 hexadecimal characters) instead of a 16 byte array, which may end up in the problem you described.

I've modified the sample provided, to encode AES 128 CBC, but the output is not as expected, my previous delphi code and his java's counterpart (made with Bouncy Castle) produce same result, which is different from the one produced with secure black box. Here is my code:

While the encrypting code generally looks fine, the actual reason for the differences you are encountering is probably somewhere in the password-to-key conversion code (as there is a number of different incompatible ways to perform the conversion). Remember that you need to perform the conversion in exactly the same way on both the encrypting and decrypting sides.

The easiest way to ensure that everything is going right is to compare values assigned to the Key and IV properties of the TElSymmetricKeyMaterial to those assigned in the decrypting Java code, provided that the same password is used. If any of the values differs, there's a problem somewhere in the conversion code that needs to be located and fixed.

Please try to decrypt the result back with both SecureBlackbox and Java code and see what outcome you get. If the data can not be decrypted at all, then something is wrong with the way the key or IV is set. If the data is decrypted and you see just the half of the text, then it's related to Unicode and the size of buffer.

We use cookies to help provide you with the best possible online experience. By using this site, you agree that we may store and access cookies on your device. You can find out more about and set your own preferences here.