Options
All
  • Public
  • Public/Protected
  • All
Menu

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

Index

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

Methods

  • decrypt(parameters: { password: ArrayBuffer }, crypto?: ICryptoEngine): Promise<ArrayBuffer>
  • Creates a new CMS Encrypted Data content

    Parameters

    • parameters: { password: ArrayBuffer }

      Parameters necessary for encryption

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

      Crypto engine

    Returns Promise<ArrayBuffer>

    Returns decrypted raw data

  • fromSchema(schema: any): void
  • toSchema(): Sequence
  • toString(encoding?: "base64" | "base64url" | "hex"): string
  • blockName(): string
  • compareWithDefault(memberName: string, memberValue: any): boolean
  • 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

  • defaultValues(memberName: "version"): number
  • defaultValues(memberName: "encryptedContentInfo"): EncryptedContentInfo
  • defaultValues(memberName: "unprotectedAttrs"): Attribute[]
  • fromBER<T>(this: PkiObjectConstructor<T>, raw: BufferSource): T
  • Creates PKI object from the raw data

    Type Parameters

    Parameters

    • this: PkiObjectConstructor<T>
    • raw: BufferSource

      ASN.1 encoded raw data

    Returns T

    Initialized and filled current class object

  • Returns value of pre-defined ASN.1 schema for current class

    asn

    ASN.1 schema

    EncryptedData ::= SEQUENCE {
       version CMSVersion,
       encryptedContentInfo EncryptedContentInfo,
       unprotectedAttrs [1] IMPLICIT UnprotectedAttributes OPTIONAL }
    

    Parameters

    Returns any

    ASN.1 schema object

Generated using TypeDoc