How to extract IV from ciphertext in XML

I have received an encrypted XML document, that contains a. An encrypted session key – this was encrypted using my public key. I have succesfully decrypted this using:

const decryptedSessionKey = crypto.privateDecrypt( { key: privKey, padding: crypto.constants.RSA_PKCS1_PADDING }, encryptedString );

b. The actual Ciphertext (UTF-8 encoded, 85228 is the character length)

c. The w3 specs suggest that the Initialisation Vector is prefixed to this cipher text, so I converted the cipher text to a Buffer, and sliced the first 16 bytes to create the IV. I then used:

const xmlIV = Buffer.from(message.slice(0, 16), ‘utf-8’);

const cryptoIv = Buffer.alloc(16, xmlIV); // Initialization vector.

const decipher = crypto.createDecipheriv(cryptoAlgorithm, decryptedSessionKey, cryptoIv);

// message.slice is removing the prefixed IV.

let decrypted = decipher.update(message.slice(16), ‘binary’, ‘binary’);

try {


} catch (err) {

console.error('Authentication failed!'); 



Decrypted is a buffer of length 85200 – which is 12 characters shorter than the message. And converting it to a utf-8 encoded string returns corrupted text.

Any superheroes out there who could help troubleshoot this ? Many thanks!