XMLSecurityConstants.secureRandom.nextBytes(iv);
IvParameterSpec ivParameterSpec = new IvParameterSpec(iv);
symmetricCipher.init(Cipher.ENCRYPT_MODE, encryptionPartDef.getSymmetricKey(), ivParameterSpec);
characterEventGeneratorOutputStream = new CharacterEventGeneratorOutputStream();
Base64OutputStream base64EncoderStream =
new Base64OutputStream(characterEventGeneratorOutputStream, true, 0, null);
base64EncoderStream.write(iv);
OutputStream outputStream = new CipherOutputStream(base64EncoderStream, symmetricCipher);
outputStream = applyTransforms(outputStream);
//the trimmer output stream is needed to strip away the dummy wrapping element which must be added
cipherOutputStream = new TrimmerOutputStream(outputStream, 8192 * 10, 3, 4);