The System.Security.Cryptography.Pkcs package gives .NET SignedCms, EnvelopedCms, CmsSigner, CmsRecipient, Pkcs12Builder, Rfc3161TimestampRequest and Rfc3161TimestampToken. OneCrypto covers the same formats with immutable models that keep their received bytes, adds the content types and recipient kinds the package lacks, and has no dependency on it. There is no SignedCms look-alike. The names below come from the package's public API documentation.
What differs in practice:
- Models are values, builders make new ones.
SignedData,EnvelopedData,AuthEnvelopedDataand the rest are read-only; there is noComputeSignatureon an existing object. - Verification is a report.
SignedCms.CheckSignature(bool verifySignatureOnly)throws on the first problem;SignedData.VerifyandCms.Verifyreturn a result per signer and per rule, and the chain check uses OneCrypto's path validator with the trust anchors you pass instead of the operating system's chain engine, so the answer is the same on every platform. - No platform key store is needed. A key can be any
ISigningKey: a PFX read byPkiIdentity.Load, an operating-system key, a token, an agent, a remote signing service. - Detached and attached are different calls, not a flag (
Cms.Sign,Cms.SignDetached). - More is supported: AuthEnvelopedData, CompressedData, every RecipientInfo kind including KEMRecipientInfo for ML-KEM, RSA-PSS and OAEP, EdDSA, ML-DSA and SLH-DSA signers, streaming in constant memory.
| Task | System.Security.Cryptography.Pkcs | OneCrypto |
|---|---|---|
| Sign (attached) | new SignedCms(new ContentInfo(data)) + ComputeSignature(new CmsSigner(cert)) + Encode() | Cms.Sign(data, certificate, key) or Cms.Sign(data, identity) or Cms.Sign(data, "signer.pfx", password) |
| Sign (detached) | new SignedCms(content, detached: true) | Cms.SignDetached(data, ...) |
| Verify | Decode(bytes), CheckSignature(true or false), SignerInfos, Certificates | Cms.Verify(message, trusted) / Cms.VerifyDetached(message, data, trusted) → SignedDataReport with Signers[i].Checks; layer: SignedData.Parse(bytes).Verify(options), .Certificates, .Signers |
| Signed attributes, signing time | CmsSigner.SignedAttributes (Pkcs9SigningTime) | CmsSignerSpec.AdditionalSignedAttributes, SigningTime; the happy path sets the signing time from the clock |
| Choose the digest or RSA-PSS | CmsSigner.DigestAlgorithm, SignerIdentifierType, RSASignaturePadding | CmsSignerSpec.DigestAlgorithm, Identifier, SignatureSpec (layer); the happy path follows the key and policy |
| Countersign | CmsSigner on SignerInfo.ComputeCounterSignature | SignedData.CreateCountersignature |
| Encrypt | new EnvelopedCms(contentInfo) + Encrypt(new CmsRecipient(cert)) | Cms.Encrypt(data, certificate) (AES-256-GCM AuthEnvelopedData); layer: EnvelopedData.Create(data, [CmsRecipient.KeyTransport(cert)]) for the CBC form S/MIME clients read |
| Decrypt | EnvelopedCms.Decode + Decrypt(recipientInfo) / Decrypt(certificates) | Cms.Decrypt(message, identity); layer: EnvelopedData.Parse(bytes).Decrypt(CmsDecryptionKey.FromKey(key, certificate)) |
| Key-agreement and ML-KEM recipients | EC key agreement through CmsRecipient; no ML-KEM | CmsRecipient.KeyAgreement(cert), CmsRecipient.Kem(cert); chosen automatically by Cms.Encrypt |
| Password and shared-key recipients | CmsRecipient with a KeyAgreeRecipientInfo only | CmsRecipient.Password(...), CmsRecipient.KeyEncryptionKey(...) |
| Large content | whole content in memory | SignedData.SignStream, VerifyStream, EnvelopedData.EncryptStream, DecryptStream and their async twins; Cms.SignDetached(Stream, Stream, ...) |
| PKCS #12 | Pkcs12Builder, Pkcs12Info, Pkcs12SafeContents, Pkcs12SafeBag | Pkcs12File.Create(...), Pkcs12File.Parse(bytes).Open(password) → Pkcs12Contents; PkiIdentity.ToPkcs12 / Load for a key with its certificate; legacy PBE encryption is readable |
| PKCS #8 | Pkcs8PrivateKeyInfo, PbeParameters | PrivateKeyInfo, EncryptedPrivateKeyInfo (Pbes2Options for the protection) |
| Certificate request | CertificateRequest in System.Security.Cryptography.X509Certificates | Pki.CreateCsr(key, name, names); layer: CertificateSigningRequestBuilder |
| Time-stamp request | Rfc3161TimestampRequest.CreateFromData(...) | TimeStampRequest.Create(new TimeStampRequestOptions { Hash, MessageImprint, ... }) |
| Time-stamp token check | Rfc3161TimestampToken.TryDecode, VerifySignatureForData | Tsa.Verify(token, data, trustedRoots) → TimeStampReport (per rule, authority trust at the token's time); layer: TimeStampVerifier.Verify(request, response, options) |
| Get a time-stamp | build the request, post it yourself | await Tsa.StampAsync(data, url, trustedRoots) (guarded transport, nothing else fetched); layer: TsaClient |
| Be a time-stamp authority | not available | TimeStampAuthority handler: parse request, return a response, you host it |
Interop
Messages are standard CMS: what SignedCms writes, Cms.Verify reads (with the trust anchors you choose), and the other way. For mail clients that cannot read AuthEnvelopedData, encrypt through the layer (EnvelopedData.Create) with CryptoPolicy.Standard: it writes AES-256-CBC and flags it; CryptoPolicy.Strict and Cnsa2 refuse it. EC key agreement is written the way Windows and openssl cms read it, and both directions are checked against openssl cms in the test suite.
Post-quantum
Cms.Sign with a key from Pki.CreateCa or Pki.IssueSigner signs with hybrid composite ML-DSA under the default policy, and ML-DSA-87 under CryptoPolicy.Cnsa2; Cms.Encrypt to a certificate from Pki.IssueEncryption uses ML-KEM key encapsulation. The package has no post-quantum support to migrate from; the same calls work with classical certificates unchanged.