CMS DigestedData
pki.cms.sign establishes origin, pki.cms.authenticate establishes origin under a shared key.
The version follows the encapsulated type, 0 for id-data and 2 for anything else. The verifying half recomputes the digest and compares it in constant time, and its verdict carries no signer and no trust field, so it cannot be read as a signature.
pki.cms.digest
pki.cms.digest(content, opts?) -> Promise<Buffer|string>
Build an RFC 5652 DigestedData: the content, the digest algorithm, and the digest over the content octets. It carries no signer and no key, so it establishes that content matches a digest and nothing about who produced either. Use pki.cms.sign for origin, or pki.cms.authenticate for origin under a shared key.
The version follows the encapsulated type, 0 for id-data and 2 for anything else.
Options
- `digestAlgorithm` (string) -- `sha256` (default), `sha384` or `sha512`.
- `contentType` (string) -- the encapsulated content type by OID name, default `data`.
- `detached` (boolean) -- omit the content, leaving the digest to travel alone.
- `pem` (boolean) -- return a PEM `CMS` block instead of DER.
Example
async function example() {
var der = await pki.cms.digest(Buffer.from("hello"));
(await pki.cms.verifyDigest(der)).valid; // -> true
}
example();
References
- spec RFC 5652 sec. 7
pki.cms.verifyDigest
pki.cms.verifyDigest(input, opts?) -> Promise<verdict>
Recompute the digest of a DigestedData's content and compare it with the digest the message carries, in constant time. Returns { valid, digestAlgorithm, content, contentType }, with code set to cms/digest-mismatch when the content does not match.
A DigestedData proves neither origin nor authority. A caller that needs either verifies a SignedData instead; this verdict carries no signer and no trust field, so it cannot be mistaken for one.
Options
- `content` (BufferSource) -- the detached content the digest covers. Required when the
message omits its own content, refused as redundant when it carries it.
Example
async function example() {
var der = await pki.cms.digest(Buffer.from("hello"));
var v = await pki.cms.verifyDigest(der);
v.valid; // -> true
v.digestAlgorithm; // -> "sha256"
}
example();
References
- spec RFC 5652 sec. 7