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
-
↳
EncryptedData
Implements
Constructors
constructor
• new EncryptedData(parameters?
): EncryptedData
Initializes a new instance of the EncryptedData class
Parameters
Name | Type | Description |
---|---|---|
parameters | EncryptedDataParameters | Initialization parameters |
Returns
Overrides
Properties
encryptedContentInfo
• encryptedContentInfo: EncryptedContentInfo
Encrypted content information
Implementation of
IEncryptedData.encryptedContentInfo
unprotectedAttrs
• Optional
unprotectedAttrs: Attribute
[]
Collection of attributes that are not encrypted
Implementation of
IEncryptedData.unprotectedAttrs
version
• version: number
Version number.
If unprotectedAttrs
is present, then the version MUST be 2. If unprotectedAttrs
is absent, then version MUST be 0.
Implementation of
CLASS_NAME
▪ Static
CLASS_NAME: string
= "EncryptedData"
Name of the class
Overrides
Accessors
className
• get
className(): string
Returns
string
Inherited from
PkiObject.className
Methods
decrypt
▸ decrypt(parameters
, crypto?
): Promise
<ArrayBuffer
>
Creates a new CMS Encrypted Data content
Parameters
Name | Type | Description |
---|---|---|
parameters | Object | Parameters necessary for encryption |
parameters.password | ArrayBuffer | - |
crypto | ICryptoEngine | Crypto engine |
Returns
Promise
<ArrayBuffer
>
Returns decrypted raw data
encrypt
▸ encrypt(parameters
, crypto?
): Promise
<void
>
Creates a new CMS Encrypted Data content
Parameters
Name | Type | Description |
---|---|---|
parameters | EncryptedDataEncryptParams | Parameters necessary for encryption |
crypto | ICryptoEngine | - |
Returns
Promise
<void
>
fromSchema
▸ fromSchema(schema
): void
Converts parsed ASN.1 object into current class
Parameters
Name | Type | Description |
---|---|---|
schema | any | ASN.1 schema |
Returns
void
Overrides
toJSON
▸ toJSON(): EncryptedDataJson
Converts the class to JSON object
Returns
JSON object
Overrides
toSchema
▸ toSchema(): Sequence
Converts current object to ASN.1 object and sets correct values
Returns
Sequence
ASN.1 object
Overrides
toString
▸ toString(encoding?
): string
Parameters
Name | Type | Default value |
---|---|---|
encoding | "base64" | "base64url" | "hex" | "hex" |
Returns
string
Inherited from
blockName
▸ blockName(): string
Returns block name
Returns
string
Returns string block name
Inherited from
compareWithDefault
▸ compareWithDefault(memberName
, memberValue
): boolean
Compare values with default values for all class members
Parameters
Name | Type | Description |
---|---|---|
memberName | string | String name for a class member |
memberValue | any | Value to compare with default value |
Returns
boolean
defaultValues
▸ defaultValues(memberName
): number
Returns default values for all class members
Parameters
Name | Type | Description |
---|---|---|
memberName | "version" | String name for a class member |
Returns
number
Default value
Overrides
▸ defaultValues(memberName
): EncryptedContentInfo
Parameters
Name | Type |
---|---|
memberName | "encryptedContentInfo" |
Returns
Overrides
PkiObject.defaultValues
▸ defaultValues(memberName
): Attribute
[]
Parameters
Name | Type |
---|---|
memberName | "unprotectedAttrs" |
Returns
Overrides
PkiObject.defaultValues
fromBER
▸ fromBER<T
>(this
, raw
): T
Creates PKI object from the raw data
Type parameters
Name | Type |
---|---|
T | extends PkiObject |
Parameters
Name | Type | Description |
---|---|---|
this | PkiObjectConstructor <T > | - |
raw | BufferSource | ASN.1 encoded raw data |
Returns
T
Initialized and filled current class object
Inherited from
schema
▸ schema(parameters?
): any
Returns value of pre-defined ASN.1 schema for current class
Parameters
Name | Type | Description |
---|---|---|
parameters | SchemaParameters <{ encryptedContentInfo? : EncryptedContentInfoSchema ; unprotectedAttrs? : string ; version? : string }> | Input parameters for the schema |
Returns
any
ASN.1 schema object