EnvelopedData
Represents the EnvelopedData structure described in RFC5652
Examples
const cmsEnveloped = new pkijs.EnvelopedData();
// Add recipient
cmsEnveloped.addRecipientByCertificate(cert, { oaepHashAlgorithm: "SHA-256" });
// Secret key algorithm
const alg = {
name: "AES-GCM",
length: 256,
}
await cmsEnveloped.encrypt(alg, dataToEncrypt);
// Add Enveloped Data into CMS Content Info
const cmsContent = new pkijs.ContentInfo();
cmsContent.contentType = pkijs.ContentInfo.ENVELOPED_DATA;
cmsContent.content = cmsEnveloped.toSchema();
const cmsContentRaw = cmsContent.toSchema().toBER();
// Get a "crypto" extension
const crypto = pkijs.getCrypto();
// Parse CMS Content Info
const cmsContent = pkijs.ContentInfo.fromBER(cmsContentRaw);
if (cmsContent.contentType !== pkijs.ContentInfo.ENVELOPED_DATA) {
throw new Error("CMS is not Enveloped Data");
}
// Parse CMS Enveloped Data
const cmsEnveloped = new pkijs.EnvelopedData({ schema: cmsContent.content });
// Export private key to PKCS#8
const pkcs8 = await crypto.exportKey("pkcs8", keys.privateKey);
// Decrypt data
const decryptedData = await cmsEnveloped.decrypt(0, {
recipientCertificate: cert,
recipientPrivateKey: pkcs8,
});
Extends
Implements
Constructors
new EnvelopedData()
new EnvelopedData(
parameters
):EnvelopedData
Initializes a new instance of the EnvelopedData class
Parameters
parameters
Initialization parameters