Recursive AI

Coming from System.Security.Cryptography.Pkcs

All onecrypto docs

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, AuthEnvelopedData and the rest are read-only; there is no ComputeSignature on an existing object.
  • Verification is a report. SignedCms.CheckSignature(bool verifySignatureOnly) throws on the first problem; SignedData.Verify and Cms.Verify return 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 by PkiIdentity.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.
TaskSystem.Security.Cryptography.PkcsOneCrypto
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, ...)
VerifyDecode(bytes), CheckSignature(true or false), SignerInfos, CertificatesCms.Verify(message, trusted) / Cms.VerifyDetached(message, data, trusted) → SignedDataReport with Signers[i].Checks; layer: SignedData.Parse(bytes).Verify(options), .Certificates, .Signers
Signed attributes, signing timeCmsSigner.SignedAttributes (Pkcs9SigningTime)CmsSignerSpec.AdditionalSignedAttributes, SigningTime; the happy path sets the signing time from the clock
Choose the digest or RSA-PSSCmsSigner.DigestAlgorithm, SignerIdentifierType, RSASignaturePaddingCmsSignerSpec.DigestAlgorithm, Identifier, SignatureSpec (layer); the happy path follows the key and policy
CountersignCmsSigner on SignerInfo.ComputeCounterSignatureSignedData.CreateCountersignature
Encryptnew 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
DecryptEnvelopedCms.Decode + Decrypt(recipientInfo) / Decrypt(certificates)Cms.Decrypt(message, identity); layer: EnvelopedData.Parse(bytes).Decrypt(CmsDecryptionKey.FromKey(key, certificate))
Key-agreement and ML-KEM recipientsEC key agreement through CmsRecipient; no ML-KEMCmsRecipient.KeyAgreement(cert), CmsRecipient.Kem(cert); chosen automatically by Cms.Encrypt
Password and shared-key recipientsCmsRecipient with a KeyAgreeRecipientInfo onlyCmsRecipient.Password(...), CmsRecipient.KeyEncryptionKey(...)
Large contentwhole content in memorySignedData.SignStream, VerifyStream, EnvelopedData.EncryptStream, DecryptStream and their async twins; Cms.SignDetached(Stream, Stream, ...)
PKCS #12Pkcs12Builder, Pkcs12Info, Pkcs12SafeContents, Pkcs12SafeBagPkcs12File.Create(...), Pkcs12File.Parse(bytes).Open(password) → Pkcs12Contents; PkiIdentity.ToPkcs12 / Load for a key with its certificate; legacy PBE encryption is readable
PKCS #8Pkcs8PrivateKeyInfo, PbeParametersPrivateKeyInfo, EncryptedPrivateKeyInfo (Pbes2Options for the protection)
Certificate requestCertificateRequest in System.Security.Cryptography.X509CertificatesPki.CreateCsr(key, name, names); layer: CertificateSigningRequestBuilder
Time-stamp requestRfc3161TimestampRequest.CreateFromData(...)TimeStampRequest.Create(new TimeStampRequestOptions { Hash, MessageImprint, ... })
Time-stamp token checkRfc3161TimestampToken.TryDecode, VerifySignatureForDataTsa.Verify(token, data, trustedRoots) → TimeStampReport (per rule, authority trust at the token's time); layer: TimeStampVerifier.Verify(request, response, options)
Get a time-stampbuild the request, post it yourselfawait Tsa.StampAsync(data, url, trustedRoots) (guarded transport, nothing else fetched); layer: TsaClient
Be a time-stamp authoritynot availableTimeStampAuthority 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.