Question
Colin Parker · May 26, 2020

I Need Help - Having AES Encryption Issues

I am using the Java Binding to connect a Java Middleware Application to Cache.  Originally I was using a CacheListOfDataTypes (JAVATYPE = "java.lang.List") object to bring data back.  I was tasked with encrypting the data using AES and I was using the AESCBCEncrypt function on the List elements (up to 20k characters for each element) to bring it back before concatenating it on the middleware.  This almost worked.  Like 95% of the characters were being decrypted correctly but some text was coming back garbled.  I couldn't understand how this was happening. I tried to adjust things like the string encoding and such, but to no effect.  Does anyone know why this might have happened??

Because of these issues I decided to try a different approach.  I now have a %BinaryGlobalStream that I am putting the data in and then I am using the AESCBCEncryptStream function once all the data is in there.  Using this method I have achieved a data transfer of a few thousand characters without any data issues.  However, when I try to perform the encryption on a larger Stream, it appears to get hung up in the Intersystems encryption functions and I have to kill the process.  Is there any limit to the size of stream that can be encrypted? The one I am working on is not even a megabyte.

Thanks for any help that can be offered.

00
1 1 3 114

Replies

Another thing I've observed.  I am playing with different length stream responses to see where things are getting hung up (and it does look like an infinite loop in the encryption functions as far as I can tell).  At a size below the infinite loop length but above the working length I am seeing this error: <ILLEGAL VALUE>zAESCBCEncryptStream+17^%SYSTEM.Encryption.1   I am not sure why an error like this would be thrown for a function that works on a stream...

Some more information.  I am populating the Stream using the .Write function but I don't want to store the Stream in a persistant fashion  since I want it to be purged after the Java Binding Connection is closed.  I have gotten the Encryption to work with a stream data length of around 28,000 characters.  When I tried to run it for 48,000 characters I got the error in the above reply.  Could this be some incarnation of a string length issue? I thought this would be avoided with the stream...

Just in case anyone else has this problem in the future, the cause was the fact that I was using the same input stream as my output stream (first two parameters of the function).  Another thing I learned is that the block encryption is performed in blocks of 32,676 bytes.  So if you are using this function you can use a buffer of that size for optimal performance on the receiving side.