Path: redb-route/redb.Route.As2/Crypto/IAs2CryptoEngine.cs Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages. License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route Page: https://redbase.app/src/dev-2026-12-06/redb-route/redb.Route.As2/Crypto/IAs2CryptoEngine.cs ---- using System.Security.Cryptography.X509Certificates; using MimeKit; using MimeKit.Cryptography; namespace redb.Route.As2.Crypto; /// /// S/MIME operations an AS2 connector needs: sign, encrypt, compress and their inverses, plus the AS2 /// Message Integrity Check. Kept behind an interface so the crypto backend is swappable (default: /// on MimeKit / Bouncy Castle — the industry AS2 foundation; escape hatch: /// Bouncy Castle .NET directly). Works on MimeKit's MIME model. /// internal interface IAs2CryptoEngine { /// Signs into a multipart/signed with our certificate. MultipartSigned Sign(MimeEntity content, X509Certificate2 signerCert, string micalg); /// Encrypts to the partner's certificate (S/MIME enveloped-data). MimeEntity Encrypt(MimeEntity content, X509Certificate2 recipientCert, string encAlg); /// Compresses (RFC 3274 compressed-data). MimeEntity Compress(MimeEntity content); /// Decrypts an S/MIME enveloped-data entity with our private key. MimeEntity Decrypt(MimeEntity encrypted, X509Certificate2 ourCert); /// /// Decrypts an S/MIME enveloped-data entity with our private key, writing the decrypted MIME entity to /// (a spool) instead of building it in memory. /// void DecryptTo(ApplicationPkcs7Mime encrypted, X509Certificate2 ourCert, Stream output); /// Decompresses an RFC 3274 compressed-data entity into (a spool). void DecompressTo(ApplicationPkcs7Mime compressed, Stream output); /// Verifies a multipart/signed against the partner's certificate. bool Verify(MultipartSigned signed, X509Certificate2 signerCert); /// Decompresses an RFC 3274 compressed-data entity. MimeEntity Decompress(MimeEntity compressed); /// /// Computes the AS2 MIC over per RFC 4130 §7.3.1. When /// is true (signed / encrypted messages) the MIME headers and content /// are hashed together, CRLF-canonicalized; when false (plain messages) only the content is hashed. /// As2Mic ComputeMic(MimeEntity part, string micalg, bool includeHeaders); /// /// The MIC of a RECEIVED signed part (RFC 4130 §7.3.1): its MIME headers and content exactly as they arrived, with /// no re-encoding. The sending side prepares a part before it signs it; the receiving side hashes what was signed. /// As2Mic ComputeReceivedMic(MimeEntity part, string micalg); }