예제 #1
0
        protected override async Task Handle(GenerateKeysRequest request, TradingChannel model)
        {
            var result  = Certificates.GenerateCertificate(model.Name);
            var builder = new StringBuilder();

            builder.AppendLine("-----BEGIN CERTIFICATE-----");
            builder.AppendLine(Convert.ToBase64String(result.Result.Export(X509ContentType.Cert), Base64FormattingOptions.InsertLineBreaks));
            builder.AppendLine("-----END CERTIFICATE-----");
            model.PublicKey  = builder.ToString();
            model.PrivateKey = Convert.ToBase64String(result.Result.Export(X509ContentType.Pkcs12), Base64FormattingOptions.InsertLineBreaks);


            //result.Result.Export(X509ContentType.Pkcs7)
            //var cert = Certificates.Get(result.PrivateKeyPem, result.PublicKeyPem,model.Name);
        }
예제 #2
0
        public string CreateCertificate(int organisationID)
        {
            CertificateSubject subject = new CertificateSubject()
            {
                CommonName  = Guid.NewGuid().ToString(),
                Organistion = organisationID.ToString()
            };
            DateTime startDate = new DateTime(DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day, 0, 0, 0, DateTimeKind.Utc);
            DateTime endDate   = startDate.AddYears(3);

            byte[] certificate = Certificates.GenerateCertificate(subject, _IssuerCA, startDate, endDate, new SignatureHashAlgorithm()
            {
                Hash = THashAlgorithm.SHA256, Signature = TSignatureAlgorithm.ECDSA
            }, DTLS.TCertificateFormat.PEM);
            return(System.Text.Encoding.UTF8.GetString(certificate));
        }