cmsSignDetached function

Uint8List cmsSignDetached({
  1. required List<int> contentDigest,
  2. required RsaPrivateKey privateKey,
  3. required List<Uint8List> certificates,
  4. DateTime? signingTime,
  5. X509Certificate? essCertificate,
  6. Hash hash = crypto.sha256,
})

Builds a detached CMS SignedData over content whose digest is contentDigest, signing with RSA PKCS#1 v1.5. certificates is the DER chain, signer certificate first. Pass essCertificate (normally the signer cert) to add the ESS signing-certificate-v2 attribute that makes the result a CAdES/PAdES baseline signature.

Implementation

Uint8List cmsSignDetached({
  required List<int> contentDigest,
  required RsaPrivateKey privateKey,
  required List<Uint8List> certificates,
  DateTime? signingTime,
  X509Certificate? essCertificate,
  crypto.Hash hash = crypto.sha256,
}) {
  final signedAttrs = cmsSignedAttributes(
    contentDigest: contentDigest,
    signingTime: signingTime,
    essCertificate: essCertificate,
    hash: hash,
  );
  final signature = rsaSign(
      privateKey, _digestOidFor(hash)!, hash.convert(signedAttrs).bytes);
  return cmsAssembleSignedData(
    signedAttributes: signedAttrs,
    signature: signature,
    certificates: certificates,
    hash: hash,
  );
}