I am wondering about when to use the managedIv method in the Apex crypto class. I noticed that if I use the managedIv method with a key from the Apex generateAESKey() method my results are always a little bit off.
As an example if I run the following in anonymous Apex it turns "Is this Working" into "Isthisworkin".
Blob key = Crypto.generateAesKey(256);
Blob testString = EncodingUtil.base64Decode('Is this working');
Blob result = Crypto.encryptWithManagedIV('AES256', key, testString );
System.debug(result);
Blob decryptedBlob = Crypto.decryptWithManagedIV('AES256', key, result);
System.debug(EncodingUtil.base64Encode(decryptedBlob));
But if run it with the Crypto.encrypt() and provide an IV with the same key it works. Can anyone tell me why this is?