Skip to content
PKIjsPKIjsPKIjsv4.0.1

EncryptedData

Represents the EncryptedData structure described in RFC5652

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();

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,
});

new EncryptedData(parameters?): EncryptedData

Initializes a new instance of the EncryptedData class

EncryptedDataParameters = {}

Initialization parameters

EncryptedData

PkiObject.constructor

encryptedContentInfo: EncryptedContentInfo

Encrypted content information

IEncryptedData.encryptedContentInfo


optional unprotectedAttrs?: Attribute[]

Collection of attributes that are not encrypted

IEncryptedData.unprotectedAttrs


version: number

Version number.

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

IEncryptedData.version


static CLASS_NAME: string = "EncryptedData"

Name of the class

PkiObject.CLASS_NAME

get className(): string

string

PkiObject.className

decrypt(parameters, crypto?): Promise<ArrayBuffer>

Creates a new CMS Encrypted Data content

Parameters necessary for encryption

ArrayBuffer

ICryptoEngine = ...

Crypto engine

Promise<ArrayBuffer>

Returns decrypted raw data


encrypt(parameters, crypto?): Promise<void>

Creates a new CMS Encrypted Data content

EncryptedDataEncryptParams

Parameters necessary for encryption

ICryptoEngine = ...

Promise<void>


fromSchema(schema): void

Converts parsed ASN.1 object into current class

any

ASN.1 schema

void

PkiObject.fromSchema


toJSON(): EncryptedDataJson

Converts the class to JSON object

EncryptedDataJson

JSON object

PkiObject.toJSON


toSchema(): Sequence

Converts current object to ASN.1 object and sets correct values

Sequence

ASN.1 object

PkiObject.toSchema


toString(encoding?): string

"hex" | "base64" | "base64url" = "hex"

string

PkiObject.toString


static blockName(): string

Returns block name

string

Returns string block name

PkiObject.blockName


static compareWithDefault(memberName, memberValue): boolean

Compare values with default values for all class members

string

String name for a class member

any

Value to compare with default value

boolean


static defaultValues(memberName): number

Returns default values for all class members

"version"

String name for a class member

number

Default value

PkiObject.defaultValues

static defaultValues(memberName): EncryptedContentInfo

Returns default values for all class members

"encryptedContentInfo"

String name for a class member

EncryptedContentInfo

Default value

PkiObject.defaultValues

static defaultValues(memberName): Attribute[]

Returns default values for all class members

"unprotectedAttrs"

String name for a class member

Attribute[]

Default value

PkiObject.defaultValues


static fromBER<T>(this, raw): T

Creates PKI object from the raw data

T extends PkiObject

PkiObjectConstructor<T>

BufferSource

ASN.1 encoded raw data

T

Initialized and filled current class object

PkiObject.fromBER


static schema(parameters?): any

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

SchemaParameters<{ encryptedContentInfo?: EncryptedContentInfoSchema; unprotectedAttrs?: string; version?: string; }> = {}

Input parameters for the schema

any

ASN.1 schema object

PkiObject.schema