How to use generateWrappingKeys method in wpt

Best JavaScript code snippet using wpt

test-webcrypto-wrap-unwrap.js

Source:test-webcrypto-wrap-unwrap.js Github

copy

Full Screen

...38 wrap: { },39 pair: false40 }41};42function generateWrappingKeys() {43 return Promise.all(Object.keys(kWrappingData).map(async (name) => {44 const keys = await subtle.generateKey(45 { name, ...kWrappingData[name].generate },46 true,47 ['wrapKey', 'unwrapKey']);48 if (kWrappingData[name].pair) {49 kWrappingData[name].wrappingKey = keys.publicKey;50 kWrappingData[name].unwrappingKey = keys.privateKey;51 } else {52 kWrappingData[name].wrappingKey = keys;53 kWrappingData[name].unwrappingKey = keys;54 }55 }));56}57async function generateKeysToWrap() {58 const parameters = [59 {60 algorithm: {61 name: 'RSASSA-PKCS1-v1_5',62 modulusLength: 1024,63 publicExponent: new Uint8Array([1, 0, 1]),64 hash: 'SHA-256'65 },66 privateUsages: ['sign'],67 publicUsages: ['verify'],68 pair: true,69 },70 {71 algorithm: {72 name: 'RSA-PSS',73 modulusLength: 1024,74 publicExponent: new Uint8Array([1, 0, 1]),75 hash: 'SHA-256'76 },77 privateUsages: ['sign'],78 publicUsages: ['verify'],79 pair: true,80 },81 {82 algorithm: {83 name: 'RSA-OAEP',84 modulusLength: 1024,85 publicExponent: new Uint8Array([1, 0, 1]),86 hash: 'SHA-256'87 },88 privateUsages: ['decrypt'],89 publicUsages: ['encrypt'],90 pair: true,91 },92 {93 algorithm: {94 name: 'ECDSA',95 namedCurve: 'P-384'96 },97 privateUsages: ['sign'],98 publicUsages: ['verify'],99 pair: true,100 },101 {102 algorithm: {103 name: 'ECDH',104 namedCurve: 'P-384'105 },106 privateUsages: ['deriveBits'],107 publicUsages: [],108 pair: true,109 },110 {111 algorithm: {112 name: 'AES-CTR',113 length: 128114 },115 usages: ['encrypt', 'decrypt'],116 pair: false,117 },118 {119 algorithm: {120 name: 'AES-CBC',121 length: 128122 },123 usages: ['encrypt', 'decrypt'],124 pair: false,125 },126 {127 algorithm: {128 name: 'AES-GCM', length: 128129 },130 usages: ['encrypt', 'decrypt'],131 pair: false,132 },133 {134 algorithm: {135 name: 'AES-KW',136 length: 128137 },138 usages: ['wrapKey', 'unwrapKey'],139 pair: false,140 },141 {142 algorithm: {143 name: 'HMAC',144 length: 128,145 hash: 'SHA-256'146 },147 usages: ['sign', 'verify'],148 pair: false,149 },150 ];151 const allkeys = await Promise.all(parameters.map(async (params) => {152 const usages = 'usages' in params ?153 params.usages :154 params.publicUsages.concat(params.privateUsages);155 const keys = await subtle.generateKey(params.algorithm, true, usages);156 if (params.pair) {157 return [158 {159 algorithm: params.algorithm,160 usages: params.publicUsages,161 key: keys.publicKey,162 },163 {164 algorithm: params.algorithm,165 usages: params.privateUsages,166 key: keys.privateKey,167 },168 ];169 }170 return [{171 algorithm: params.algorithm,172 usages: params.usages,173 key: keys,174 }];175 }));176 return allkeys.flat();177}178function getFormats(key) {179 switch (key.key.type) {180 case 'secret': return ['raw', 'jwk'];181 case 'public': return ['spki', 'jwk'];182 case 'private': return ['pkcs8', 'jwk'];183 }184}185// If the wrapping algorithm is AES-KW, the exported key186// material length must be a multiple of 8.187// If the wrapping algorithm is RSA-OAEP, the exported key188// material maximum length is a factor of the modulusLength189async function wrappingIsPossible(name, exported) {190 if ('byteLength' in exported) {191 switch (name) {192 case 'AES-KW':193 return exported.byteLength % 8 === 0;194 case 'RSA-OAEP':195 return exported.byteLength <= 446;196 }197 } else if ('kty' in exported) {198 switch (name) {199 case 'AES-KW':200 return JSON.stringify(exported).length % 8 === 0;201 case 'RSA-OAEP':202 return JSON.stringify(exported).length <= 478;203 }204 }205 return true;206}207async function testWrap(wrappingKey, unwrappingKey, key, wrap, format) {208 const exported = await subtle.exportKey(format, key.key);209 if (!(await wrappingIsPossible(wrappingKey.algorithm.name, exported)))210 return;211 const wrapped =212 await subtle.wrapKey(213 format,214 key.key,215 wrappingKey,216 { name: wrappingKey.algorithm.name, ...wrap });217 const unwrapped =218 await subtle.unwrapKey(219 format,220 wrapped,221 unwrappingKey,222 { name: wrappingKey.algorithm.name, ...wrap },223 key.algorithm,224 true,225 key.usages);226 assert(unwrapped.extractable);227 const exportedAgain = await subtle.exportKey(format, unwrapped);228 assert.deepStrictEqual(exported, exportedAgain);229}230async function testWrapping(name, keys) {231 const variations = [];232 const {233 wrappingKey,234 unwrappingKey,235 wrap236 } = kWrappingData[name];237 keys.forEach((key) => {238 getFormats(key).forEach((format) => {239 variations.push(testWrap(wrappingKey, unwrappingKey, key, wrap, format));240 });241 });242 return Promise.all(variations);243}244(async function() {245 await generateWrappingKeys();246 const keys = await generateKeysToWrap();247 const variations = [];248 Object.keys(kWrappingData).forEach((name) => {249 return testWrapping(name, keys);250 });251 await Promise.all(variations);...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptEncryption = require('wpt-encryption');2var encryption = new wptEncryption();3var wrappingKeys = encryption.generateWrappingKeys();4console.log(wrappingKeys);5var wptEncryption = require('wpt-encryption');6var encryption = new wptEncryption();7var encrypted = encryption.encrypt("Hello World");8console.log(encrypted);9var wptEncryption = require('wpt-encryption');10var encryption = new wptEncryption();11var decrypted = encryption.decrypt("Hello World");12console.log(decrypted);13var wptEncryption = require('wpt-encryption');14var encryption = new wptEncryption();15var encrypted = encryption.encryptWithWrappingKey("Hello World", "WrappingKey");16console.log(encrypted);17var wptEncryption = require('wpt-encryption');18var encryption = new wptEncryption();19var decrypted = encryption.decryptWithWrappingKey("Hello World", "WrappingKey");20console.log(decrypted);21var wptEncryption = require('wpt-encryption');22var encryption = new wptEncryption();23var encrypted = encryption.encryptWithWrappingKey("Hello World", "WrappingKey");24console.log(encrypted);25var wptEncryption = require('wpt-encryption');26var encryption = new wptEncryption();27var decrypted = encryption.decryptWithWrappingKey("Hello World", "WrappingKey");28console.log(decrypted);29var wptEncryption = require('wpt-encryption');30var encryption = new wptEncryption();31var encrypted = encryption.encryptWithWrappingKey("Hello World", "WrappingKey");32console.log(encrypted);

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2var wpt = new wpt('API_KEY');3wpt.generateWrappingKeys(function(err, data) {4 console.log(data);5});6var wpt = require('wpt');7var wpt = new wpt('API_KEY');8wpt.getLocations(function(err, data) {9 console.log(data);10});11var wpt = require('wpt');12var wpt = new wpt('API_KEY');13wpt.getTesters(function(err, data) {14 console.log(data);15});16var wpt = require('wpt');17var wpt = new wpt('API_KEY');18wpt.getTestersByLocation('Dulles:Chrome', function(err, data) {19 console.log(data);20});21var wpt = require('wpt');22var wpt = new wpt('API_KEY');23wpt.getTestersByLocation('Dulles:Chrome', function(err, data) {24 console.log(data);25});26var wpt = require('wpt');27var wpt = new wpt('API_KEY');28wpt.getTestStatus('140527_2P_2', function(err, data) {29 console.log(data);30});31var wpt = require('wpt');32var wpt = new wpt('API_KEY');33wpt.getTestResults('140527_2P_2', function(err, data) {34 console.log(data);35});36var wpt = require('wpt');37var wpt = new wpt('API_KEY');38wpt.getTestResults('140527_2P_2', function(err, data) {39 console.log(data);40});

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful