SignedData
Represents the SignedData structure described in RFC5652
Examples
Section titled “Examples”The following example demonstrates how to create and sign CMS Signed Data
// Create a new CMS Signed Dataconst cmsSigned = new pkijs.SignedData({ encapContentInfo: new pkijs.EncapsulatedContentInfo({ eContentType: pkijs.ContentInfo.DATA,, // "data" content type eContent: new asn1js.OctetString({ valueHex: buffer }) }), signerInfos: [ new pkijs.SignerInfo({ sid: new pkijs.IssuerAndSerialNumber({ issuer: cert.issuer, serialNumber: cert.serialNumber }) }) ], // Signer certificate for chain validation certificates: [cert]});
await cmsSigned.sign(keys.privateKey, 0, "SHA-256");
// Add Signed Data to Content Infoconst cms = new pkijs.ContentInfo({ contentType: pkijs.ContentInfo.SIGNED_DATA,, content: cmsSigned.toSchema(true),});
// Encode CMS to ASN.1const cmsRaw = cms.toSchema().toBER();The following example demonstrates how to verify CMS Signed Data
// Parse CMS and detect it's Signed Dataconst cms = pkijs.ContentInfo.fromBER(cmsRaw);if (cms.contentType !== pkijs.ContentInfo.SIGNED_DATA) { throw new Error("CMS is not Signed Data");}
// Read Signed Dataconst signedData = new pkijs.SignedData({ schema: cms.content });
// Verify Signed Data signatureconst ok = await signedData.verify({ signer: 0, checkChain: true, trustedCerts: [trustedCert],});
if (!ok) { throw new Error("CMS signature is invalid")}Extends
Section titled “Extends”Implements
Section titled “Implements”Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new SignedData(
parameters?):SignedData
Initializes a new instance of the SignedData class
Parameters
Section titled “Parameters”parameters?
Section titled “parameters?”SignedDataParameters = {}
Initialization parameters
Returns
Section titled “Returns”SignedData
Overrides
Section titled “Overrides”Properties
Section titled “Properties”certificates?
Section titled “certificates?”
optionalcertificates?:CertificateSetItem[]
Implementation of
Section titled “Implementation of”
optionalcrls?:SignedDataCRL[]
Implementation of
Section titled “Implementation of”digestAlgorithms
Section titled “digestAlgorithms”digestAlgorithms:
AlgorithmIdentifier[]
Implementation of
Section titled “Implementation of”encapContentInfo
Section titled “encapContentInfo”encapContentInfo:
EncapsulatedContentInfo
Implementation of
Section titled “Implementation of”ocsps?
Section titled “ocsps?”
optionalocsps?:BasicOCSPResponse[]
Implementation of
Section titled “Implementation of”signerInfos
Section titled “signerInfos”signerInfos:
SignerInfo[]
Implementation of
Section titled “Implementation of”version
Section titled “version”version:
number
Implementation of
Section titled “Implementation of”CLASS_NAME
Section titled “CLASS_NAME”
staticCLASS_NAME:string="SignedData"
Name of the class
Overrides
Section titled “Overrides”ID_DATA
Section titled “ID_DATA”
staticID_DATA:"1.2.840.113549.1.7.1"=id_ContentType_Data
Accessors
Section titled “Accessors”className
Section titled “className”Get Signature
Section titled “Get Signature”get className():
string
Returns
Section titled “Returns”string
Inherited from
Section titled “Inherited from”Methods
Section titled “Methods”fromSchema()
Section titled “fromSchema()”fromSchema(
schema):void
Converts parsed ASN.1 object into current class
Parameters
Section titled “Parameters”schema
Section titled “schema”any
ASN.1 schema
Returns
Section titled “Returns”void
Overrides
Section titled “Overrides”sign()
Section titled “sign()”sign(
privateKey,signerIndex,hashAlgorithm?,data?,crypto?):Promise<void>
Signing current SignedData
Parameters
Section titled “Parameters”privateKey
Section titled “privateKey”CryptoKey
Private key for “subjectPublicKeyInfo” structure
signerIndex
Section titled “signerIndex”number
Index number (starting from 0) of signer index to make signature for
hashAlgorithm?
Section titled “hashAlgorithm?”string = "SHA-1"
Hashing algorithm. Default SHA-1
BufferSource = EMPTY_BUFFER
Detached data
crypto?
Section titled “crypto?”ICryptoEngine = ...
Crypto engine
Returns
Section titled “Returns”Promise<void>
toJSON()
Section titled “toJSON()”toJSON():
SignedDataJson
Converts the class to JSON object
Returns
Section titled “Returns”JSON object
Overrides
Section titled “Overrides”toSchema()
Section titled “toSchema()”toSchema(
encodeFlag?):any
Converts current object to ASN.1 object and sets correct values
Parameters
Section titled “Parameters”encodeFlag?
Section titled “encodeFlag?”boolean = false
If param equal to false then creates schema via decoding stored value. In other case creates schema via assembling from cached parts
Returns
Section titled “Returns”any
ASN.1 object
Overrides
Section titled “Overrides”toString()
Section titled “toString()”toString(
encoding?):string
Parameters
Section titled “Parameters”encoding?
Section titled “encoding?”"hex" | "base64" | "base64url" = "hex"
Returns
Section titled “Returns”string
Inherited from
Section titled “Inherited from”verify()
Section titled “verify()”Call Signature
Section titled “Call Signature”verify(
params?,crypto?):Promise<boolean>
Parameters
Section titled “Parameters”params?
Section titled “params?”SignedDataVerifyParams & object
crypto?
Section titled “crypto?”Returns
Section titled “Returns”Promise<boolean>
Call Signature
Section titled “Call Signature”verify(
params,crypto?):Promise<SignedDataVerifyResult>
Parameters
Section titled “Parameters”params
Section titled “params”SignedDataVerifyParams & object
crypto?
Section titled “crypto?”Returns
Section titled “Returns”Promise<SignedDataVerifyResult>
blockName()
Section titled “blockName()”
staticblockName():string
Returns block name
Returns
Section titled “Returns”string
Returns string block name
Inherited from
Section titled “Inherited from”compareWithDefault()
Section titled “compareWithDefault()”
staticcompareWithDefault(memberName,memberValue):boolean
Compare values with default values for all class members
Parameters
Section titled “Parameters”memberName
Section titled “memberName”string
String name for a class member
memberValue
Section titled “memberValue”any
Value to compare with default value
Returns
Section titled “Returns”boolean
defaultValues()
Section titled “defaultValues()”Call Signature
Section titled “Call Signature”
staticdefaultValues(memberName):number
Returns default values for all class members
Parameters
Section titled “Parameters”memberName
Section titled “memberName”"version"
String name for a class member
Returns
Section titled “Returns”number
Default value
Overrides
Section titled “Overrides”Call Signature
Section titled “Call Signature”
staticdefaultValues(memberName):AlgorithmIdentifier[]
Returns default values for all class members
Parameters
Section titled “Parameters”memberName
Section titled “memberName”"digestAlgorithms"
String name for a class member
Returns
Section titled “Returns”Default value
Overrides
Section titled “Overrides”PkiObject.defaultValues
Call Signature
Section titled “Call Signature”
staticdefaultValues(memberName):EncapsulatedContentInfo
Returns default values for all class members
Parameters
Section titled “Parameters”memberName
Section titled “memberName”"encapContentInfo"
String name for a class member
Returns
Section titled “Returns”Default value
Overrides
Section titled “Overrides”PkiObject.defaultValues
Call Signature
Section titled “Call Signature”
staticdefaultValues(memberName):CertificateSetItem[]
Returns default values for all class members
Parameters
Section titled “Parameters”memberName
Section titled “memberName”"certificates"
String name for a class member
Returns
Section titled “Returns”Default value
Overrides
Section titled “Overrides”PkiObject.defaultValues
Call Signature
Section titled “Call Signature”
staticdefaultValues(memberName):SignedDataCRL[]
Returns default values for all class members
Parameters
Section titled “Parameters”memberName
Section titled “memberName”"crls"
String name for a class member
Returns
Section titled “Returns”Default value
Overrides
Section titled “Overrides”PkiObject.defaultValues
Call Signature
Section titled “Call Signature”
staticdefaultValues(memberName):BasicOCSPResponse[]
Returns default values for all class members
Parameters
Section titled “Parameters”memberName
Section titled “memberName”"ocsps"
String name for a class member
Returns
Section titled “Returns”Default value
Overrides
Section titled “Overrides”PkiObject.defaultValues
Call Signature
Section titled “Call Signature”
staticdefaultValues(memberName):SignerInfo[]
Returns default values for all class members
Parameters
Section titled “Parameters”memberName
Section titled “memberName”"signerInfos"
String name for a class member
Returns
Section titled “Returns”Default value
Overrides
Section titled “Overrides”PkiObject.defaultValues
fromBER()
Section titled “fromBER()”
staticfromBER<T>(this,raw):T
Creates PKI object from the raw data
Type Parameters
Section titled “Type Parameters”T extends PkiObject
Parameters
Section titled “Parameters”PkiObjectConstructor<T>
BufferSource
ASN.1 encoded raw data
Returns
Section titled “Returns”T
Initialized and filled current class object
Inherited from
Section titled “Inherited from”schema()
Section titled “schema()”
staticschema(parameters?):any
Returns value of pre-defined ASN.1 schema for current class
Parameters
Section titled “Parameters”parameters?
Section titled “parameters?”SchemaParameters<{ certificates?: string; crls?: RevocationInfoChoicesSchema; digestAlgorithms?: string; encapContentInfo?: EncapsulatedContentInfoSchema; signerInfos?: string; version?: string; }> = {}
Input parameters for the schema
Returns
Section titled “Returns”any
ASN.1 schema object