Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return new Promise((resolve, reject) => {
const size = algorithm.modulusLength;
const exp = new Buffer(algorithm.publicExponent);
const template = create_template(session!, algorithm as any, extractable, keyUsages);
// RSA params
template.publicKey.publicExponent = exp;
template.publicKey.modulusBits = size;
// PKCS11 generation
session!.generateKeyPair(KeyGenMechanism.RSA, template.publicKey, template.privateKey, (err, keys) => {
try {
if (err) {
reject(new WebCryptoError(`Rsa: Can not generate new key\n${err.message}`));
} else {
const wcKeyPair: CryptoKeyPair = {
privateKey: new RsaCryptoKey(keys.privateKey, algorithm),
publicKey: new RsaCryptoKey(keys.publicKey, algorithm),
};
resolve(wcKeyPair);
}
} catch (e) {
reject(e);
}
});
});
});
return new Promise((resolve, reject) => {
session.generateKeyPair(KeyGenMechanism.RSA, template.publicKey, template.privateKey, (err, keys) => {
try {
if (err) {
reject(new core.CryptoError(`Rsa: Can not generate new key\n${err.message}`));
} else {
const wcKeyPair = {
privateKey: new RsaCryptoKey(keys.privateKey, algorithm as RsaHashedKeyAlgorithm),
publicKey: new RsaCryptoKey(keys.publicKey, algorithm as RsaHashedKeyAlgorithm),
};
resolve(wcKeyPair as any);
}
} catch (e) {
reject(e);
}
});
});
}