Class EncryptedData

Represents the EncryptedData structure described in RFC5652

Example

The following example demonstrates how to create and encrypt CMS Encrypted Data

const cmsEncrypted = new pkijs.EncryptedData();

await cmsEncrypted.encrypt({
contentEncryptionAlgorithm: {
name: "AES-GCM",
length: 256,
},
hmacHashAlgorithm: "SHA-256",
iterationCount: 1000,
password: password,
contentToEncrypt: dataToEncrypt,
});

// Add Encrypted Data into CMS Content Info
const cmsContent = new pkijs.ContentInfo();
cmsContent.contentType = pkijs.ContentInfo.ENCRYPTED_DATA;
cmsContent.content = cmsEncrypted.toSchema();

const cmsContentRaw = cmsContent.toSchema().toBER();

Example

The following example demonstrates how to decrypt CMS Encrypted Data

// Parse CMS Content Info
const cmsContent = pkijs.ContentInfo.fromBER(cmsContentRaw);
if (cmsContent.contentType !== pkijs.ContentInfo.ENCRYPTED_DATA) {
throw new Error("CMS is not Encrypted Data");
}
// Parse CMS Encrypted Data
const cmsEncrypted = new pkijs.EncryptedData({ schema: cmsContent.content });

// Decrypt data
const decryptedData = await cmsEncrypted.decrypt({
password: password,
});

Hierarchy

Implements

Constructors

Properties

encryptedContentInfo: EncryptedContentInfo

Encrypted content information

unprotectedAttrs?: Attribute[]

Collection of attributes that are not encrypted

version: number

Version number.

If unprotectedAttrs is present, then the version MUST be 2. If unprotectedAttrs is absent, then version MUST be 0.

CLASS_NAME: string = "EncryptedData"

Name of the class

Accessors

  • get className(): string
  • Returns string

Methods

  • Creates a new CMS Encrypted Data content

    Returns

    Returns decrypted raw data

    Parameters

    • parameters: { password: ArrayBuffer }

      Parameters necessary for encryption

      • password: ArrayBuffer
    • crypto: ICryptoEngine = ...

      Crypto engine

    Returns Promise<ArrayBuffer>

  • Parameters

    • encoding: "base64" | "base64url" | "hex" = "hex"

    Returns string

  • Compare values with default values for all class members

    Parameters

    • memberName: string

      String name for a class member

    • memberValue: any

      Value to compare with default value

    Returns boolean

  • Creates PKI object from the raw data

    Returns

    Initialized and filled current class object

    Type Parameters

    Parameters

    • this: PkiObjectConstructor<T>
    • raw: BufferSource

      ASN.1 encoded raw data

    Returns T

Generated using TypeDoc