SignedData
Represents the SignedData structure described in RFC5652
Examples
// Create a new CMS Signed Data
const 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 Info
const cms = new pkijs.ContentInfo({
contentType: pkijs.ContentInfo.SIGNED_DATA,,
content: cmsSigned.toSchema(true),
});
// Encode CMS to ASN.1
const cmsRaw = cms.toSchema().toBER();
// Parse CMS and detect it's Signed Data
const cms = pkijs.ContentInfo.fromBER(cmsRaw);
if (cms.contentType !== pkijs.ContentInfo.SIGNED_DATA) {
throw new Error("CMS is not Signed Data");
}
// Read Signed Data
const signedData = new pkijs.SignedData({ schema: cms.content });
// Verify Signed Data signature
const ok = await signedData.verify({
signer: 0,
checkChain: true,
trustedCerts: [trustedCert],
});
if (!ok) {
throw new Error("CMS signature is invalid")
}
Extends
Implements
Constructors
new SignedData()
new SignedData(
parameters
):SignedData
Initializes a new instance of the SignedData class
Parameters
parameters
SignedDataParameters
= {}
Initialization parameters
Returns
Overrides
Properties
certificates?
optional
certificates:CertificateSetItem
[]
Implementation of
crls?
optional
crls:SignedDataCRL
[]
Implementation of
digestAlgorithms
digestAlgorithms:
AlgorithmIdentifier
[]
Implementation of
encapContentInfo
encapContentInfo:
EncapsulatedContentInfo
Implementation of
ocsps?
optional
ocsps:BasicOCSPResponse
[]
Implementation of
signerInfos
signerInfos:
SignerInfo
[]
Implementation of
version
version:
number
Implementation of
CLASS_NAME
static
CLASS_NAME:string
="SignedData"
Name of the class
Overrides
ID_DATA
static
ID_DATA:"1.2.840.113549.1.7.1"
=id_ContentType_Data
Accessors
className
Get Signature
get className():
string
Returns
string
Inherited from
Methods
fromSchema()
fromSchema(
schema
):void
Converts parsed ASN.1 object into current class
Parameters
schema
any
ASN.1 schema
Returns
void
Overrides
sign()
sign(
privateKey
,signerIndex
,hashAlgorithm
,data
,crypto
):Promise
<void
>
Signing current SignedData
Parameters
privateKey
CryptoKey
Private key for "subjectPublicKeyInfo" structure
signerIndex
number
Index number (starting from 0) of signer index to make signature for
hashAlgorithm
string
= "SHA-1"
Hashing algorithm. Default SHA-1
data
BufferSource
= ...
Detached data
crypto
ICryptoEngine
= ...
Crypto engine
Returns
Promise
<void
>
toJSON()
toJSON():
SignedDataJson
Converts the class to JSON object