diff --git a/src/services/reports.js b/src/services/reports.js index 5e69549..80f773c 100644 --- a/src/services/reports.js +++ b/src/services/reports.js @@ -45,11 +45,11 @@ export const sendPDFExport = (authToken, applet, activities, appletResponse, cur }) } - const encrypted = crypto.publicEncrypt(configs.publicEncryptionKey, Buffer.from(JSON.stringify(params))); + const encrypted = encryptData(configs.publicEncryptionKey, JSON.stringify(params)); exportPDF( configs.serverIp, authToken, - encrypted.toString('base64'), + encrypted, applet.id.split('/').pop(), flowId && flowId.split('/').pop(), currentActivityId.split('/').pop(), @@ -57,3 +57,14 @@ export const sendPDFExport = (authToken, applet, activities, appletResponse, cur ) } } + +function encryptData(publicKey, data) { + const encrypted = []; + const chunkSize = parseInt(publicKey.length * 0.58); + const array = Buffer.from(data); + for (let i = 0; i < array.length; i += chunkSize) { + const chunk = array.slice(i, i + chunkSize); + encrypted.push(crypto.publicEncrypt(publicKey, chunk).toString('base64')); + } + return encrypted; +}