Path: redb-route/demo/SerialNumbersDemo/SerialNumbers.Worker/DemoCertificates.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/demo/SerialNumbersDemo/SerialNumbers.Worker/DemoCertificates.cs ---- using System.Security.Cryptography; using System.Security.Cryptography.X509Certificates; namespace SerialNumbers.Worker; /// /// Self-signed AS2 certificates for the demo: one pair for the hub, one for the simulated partner /// GLOBEX. Each side keeps its private key (.pfx) and hands the other side its public /// certificate (.cer). Real partners exchange certificates issued for the partnership. /// public static class DemoCertificates { public static void EnsureCreated(string directory, string password) { Directory.CreateDirectory(directory); EnsurePair(directory, "hub", "SERIALS-HUB", password); EnsurePair(directory, "globex", "GLOBEX", password); } private static void EnsurePair(string directory, string name, string commonName, string password) { var pfxPath = Path.Combine(directory, $"{name}.pfx"); var cerPath = Path.Combine(directory, $"{name}.cer"); if (File.Exists(pfxPath) && File.Exists(cerPath)) return; using var rsa = RSA.Create(2048); var request = new CertificateRequest($"CN={commonName}", rsa, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1); using var certificate = request.CreateSelfSigned(DateTimeOffset.UtcNow.AddDays(-1), DateTimeOffset.UtcNow.AddYears(5)); File.WriteAllBytes(pfxPath, certificate.Export(X509ContentType.Pkcs12, password)); File.WriteAllBytes(cerPath, certificate.Export(X509ContentType.Cert)); } }