const jose = require('node-jose'); var preEncryptionRequest = { data: { "paymentInformation": { "card": { "expirationYear": "22", "number": "[place PAN Here]", "expirationMonth": "05", "securityCode": "122" } } }, context: 'eyJraWQiOiIzZyIsImFsZyI6IlJTMjU2In0.eyJmbHgiOnsicGF0aCI6Ii9mbGV4L3YyL3Rva2VucyIsImRhdGEiOiJuVmRVWWdVN0lkdFlxT2RlS1lUOWh4QUFFSExpTFlPeXJRQXRuaDY4YmRWUjZ3TUlBL2VuUVpvZDNnZ2VpYU9TcVFjSzJDQjgyWDdQZ1Y0cWJxOGRIZ0lsaThZUC9QUTVMTzRsU1A1MWhkb3pDS2d4cmFqZnFIc1FpUjk3VlVJSWFRZk4iLCJvcmlnaW4iOiJodHRwczovL3Rlc3RmbGV4LmN5YmVyc291cmNlLmNvbSIsImp3ayI6eyJrdHkiOiJSU0EiLCJlIjoiQVFBQiIsInVzZSI6ImVuYyIsIm4iOiJyN3hXMWk3QUZwVFJaWjEzYTNtelZrRG5jVXQ2enFjOUdTX3llb2J1elU0WG8tQUotMDhuSkxQUVN0V2RWa0psUUVkVjdqenJVYXZOblpOeWdzVFNiOXJySE9Bd0loNEM0ZVpaR09VUW5QellaRktTam5RY05QSGFJZ0w1RENTWUlleWFDTC0taDZQZTQ1dmJHLUxCZkRBTFk3NGw1R2dhVFlBTWgySlhCYy1KaVowRGF3ODUzaUVuRkVQWkswbW8zbk42TWlXUExaWUI5d2U5N01PUkdRTF83aE9ROGh4QXhQX0VKT3ZMNEJEbE5GX182SUxCMksySXBSS1hGOVM4czR2Ni1CX3dDRUFKdDVSd1FtNGttN2MtU1lrUUhNNHZCS2Ezd0Y2X1JLU3lYZlpTb0hjeU1rSTdfSTV4Q3Y3NGlabkZ3TGd0S0M1d3BJOEpqSWtXenciLCJraWQiOiIwOGw1QWxKVzhWdXM0ejJURmtKWklrZU1lblR4MWlYYSJ9fSwiY3R4IjpbeyJkYXRhIjp7InJlcXVpcmVkRmllbGRzIjpbInBheW1lbnRJbmZvcm1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50SW5mb3JtYXRpb24uY2FyZC5leHBpcmF0aW9uWWVhciIsIm9yZGVySW5mb3JtYXRpb24uc2hpcFRvLmFkbWluaXN0cmF0aXZlQXJlYSIsIm9yZGVySW5mb3JtYXRpb24uYmlsbFRvLmFkZHJlc3MyIiwicGF5bWVudEluZm9ybWF0aW9uLmNhcmQuZXhwaXJhdGlvbk1vbnRoIiwib3JkZXJJbmZvcm1hdGlvbi5zaGlwVG8uY291bnRyeSIsIm9yZGVySW5mb3JtYXRpb24uYmlsbFRvLmFkZHJlc3MxIiwicGF5bWVudEluZm9ybWF0aW9uLmNhcmQuc2VjdXJpdHlDb2RlIiwib3JkZXJJbmZvcm1hdGlvbi5zaGlwVG8ubG9jYWxpdHkiLCJvcmRlckluZm9ybWF0aW9uLnNoaXBUby5jb21wYW55Il19LCJ0eXBlIjoiYXBpLTAuMS4wIn1dLCJpc3MiOiJGbGV4IEFQSSIsImV4cCI6MTYxOTQ2OTg5MSwiaWF0IjoxNjE5NDY4OTkxLCJqdGkiOiJNa29zT2FaM1FoM2N5MGk4In0.Onzufhz0HetjfAsEz84XG5Vkrqm60napZSWsIZZEeAkrDjE7KSWsZ-zZMn0mPAo-ZC4C0WbKYfM9cYct7kTcMykT9xphxcxIoMbfE2MiJfBCMbGvmfg13aOA9x8TzuZYlvr-BVCdRf9GI2Cq-aAvfM37nl_B5C66yywDL00sprPE6TkisNDWKYtSN03XFoT0Rl2I32-TJxnN6RMmUPjJqh8e81X2cIJqsLcv43bZmTSYZHJQK8dQmV2YTA8u8hupTAohWWVOZ4fx3MmSmevpTVep4QZp-A3HwyThBOsXVmjy4j1ezqbecRMAyS2CU_9NSPB6tLtH_2oeOMdLi-iK8Q', index: 0 }; var payload = JSON.stringify(preEncryptionRequest); function calculateJWE(payload) { // console.log('\nSample: Construct JWE for Cybersource Token Request'); console.log('\n*************** Parsing CC & Extracting JWK ********************* '); // Parse the Capture Context from the context element of the input payload, base 64 decode & extract the JWK var ccBody = JSON.parse(payload).context.split('.')[1]; var atob = require('atob'); var decodedValue = JSON.parse(atob(ccBody)); var jwk = decodedValue.flx.jwk; console.log("JWK =", jwk, "\n"); // Creating keystore input const webkey = { "keys": [ JSON.stringify(jwk) ] }; //Generate key store from public JWK jose.JWK.asKeyStore(webkey). then((result) => { let keyStore = result; //get the key to encrypt const encryptionKey = keyStore.get(webkey.keys[0].kid); //passing input as buffer const input = jose.util.asBuffer(payload); //encryption paramiters let contentAlg = "A256GCM"; let options = { contentAlg: contentAlg, compact: true, }; //Constructing JWE jose.JWE.createEncrypt(options, encryptionKey). update(input). final(). then((jweInGeneralSerialization) => { console.log("Encryption result", JSON.stringify(jweInGeneralSerialization)); console.log('\n*************** JWE ********************* '); console.log(jweInGeneralSerialization); return jweInGeneralSerialization; }); }); } if (require.main === module) { calculateJWE(payload); } module.exports.calculateJWE = calculateJWE;
Write, Run & Share NodeJS code online using OneCompiler's NodeJS online compiler for free. It's one of the robust, feature-rich online compilers for NodeJS language,running on the latest LTS version NodeJS 16.14.2. Getting started with the OneCompiler's NodeJS editor is easy and fast. The editor shows sample boilerplate code when you choose language as NodeJS and start coding. You can provide the dependencies in package.json
.
Node.js is a free and open-source server environment. Node.js is very popular in recent times and a large number of companies like Microsoft, Paypal, Uber, Yahoo, General Electric and many others are using Node.js.
Google chrome's javascript engine V8
and is pretty fast.Asynchronous
, event-driven
and works on single-thread model
thus eliminating the dis-advantages of multi-thread model.Express is one of the most popular web application framework in the NodeJS echosystem.
let moment = require('moment');
console.log(moment().format('MMMM Do YYYY, h:mm:ss a'));
const _ = require("lodash");
let colors = ['blue', 'green', 'yellow', 'red'];
let firstElement = _.first(colors);
let lastElement = _.last(colors);
console.log(`First element: ${firstElement}`);
console.log(`Last element: ${lastElement}`);
Following are the libraries supported by OneCompiler's NodeJS compiler.