watzen / wtz_file_crypto_suiteapp Goto Github PK
View Code? Open in Web Editor NEWA proof of concept for OpenPGP Encrypting and Decrypting files in Netsuite using the OpenPGP.js library
A proof of concept for OpenPGP Encrypting and Decrypting files in Netsuite using the OpenPGP.js library
While trying to implement a simple PGP encryption solution using your PGP library in lib
folder , i run into this error :
TypeError: global.Set is not a constructor [at Object.<anonymous> (/SuiteScripts/Third Party PGP Solution/lib/openpgp.js:31665:39)]
I had been trying to use OpenPGP.js for a long time when I stumbled upon your solution. In my expedition, I always ran into the issue of not converting OpenPGP to AMD fully because of so many dependencies on Node or Browser. Your solution seems to be working because you also included the TextEncoder
that I was not able to implement. But now I have ran into this issue.
Would you please help me out?
P.S. this is my Map/Reduce file :
/**
* @NApiVersion 2.1
* @NScriptType MapReduceScript
*/
define(["N/file", "N/log", "./lib/openpgp.js"], function (file, log, openpgp) {
/* ================== ENCRYPT FILE ======================== */
async function encryptPGP(params) {
const publicKeyArmored = params.publicKeyArmored;
const inputFileContents = params.inputFileContents;
const isText = params.isText;
const encryptMessage = isText
? openpgp.message.fromText(inputFileContents)
: openpgp.message.fromBinary(inputFileContents);
const publicKeys = (await openpgp.key.readArmored(publicKeyArmored)).keys;
const encryptionResult = await openpgp.encrypt({
message: encryptMessage,
publicKeys: publicKeys,
});
const encrypted = encryptionResult.data;
return encrypted;
}
/* ======================== MAIN FUNCTION ======================= */
async function mainAsyncExecution(processingObj) {
log.debug("mainAsyncExecution - start -", processingObj);
const inputFile = file.load({
id: processingObj.inputFileId,
}); //10 units
const publicKeyFile = file.load({
id: processingObj.publicKeyFileId,
}); //10 units
await Promise.all([inputFile, publicKeyFile]); //wait for the two inputFileContents and cryptoType loads to complete
const inputFileContents = inputFile.isText
? inputFile.getContents()
: Base64Binary.decode(inputFile.getContents());
const publicKeyFileContents = publicKeyFile.isText
? publicKeyFile.getContents()
: Base64Binary.decode(publicKeyFile.getContents());
log.debug("inputFileContents", inputFileContents);
log.debug("publicKeyFileContents", publicKeyFileContents);
const outputFolderId = processingObj.outputFolderId;
let newFileId;
let encryptedContents = await encryptPGP({
publicKeyArmored: publicKeyFileContents,
inputFileContents: inputFileContents,
isText: inputFile.isText,
});
const newFile = file.create({
name: inputFile.name + ".pgp",
fileType: file.Type.PLAINTEXT,
contents: encryptedContents,
folder: outputFolderId,
});
newFileId = newFile.save();
log.debug("mainAsyncExecution", "new encrypted fileId:" + newFileId);
return newFileId;
}
function getInputData() {
return { myKey: "1" };
}
function map(mapContext) {
const key = JSON.parse(mapContext.key);
const value = JSON.parse(mapContext.value);
mapContext.write({ key: key, value: value });
}
function reduce(reduceContext) {
const executionOptions = {
inputFileId: "856",
outputFolderId: "44",
publicKeyFileId: "808",
};
mainAsyncExecution(executionOptions);
}
return { getInputData: getInputData, map: map, reduce: reduce };
});
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.