Пример #1
0
        private void CreateClientKeyCertificatePair()
        {
            var commonCertifName = "CN=" + GrpcConstants.DefaultTlsCommonName;

            var rsaKeyPair        = TlsHelper.GenerateRsaKeyPair();
            var clientCertificate = TlsHelper.GenerateCertificate(new X509Name(commonCertifName),
                                                                  new X509Name(commonCertifName), rsaKeyPair.Private, rsaKeyPair.Public);

            _clientKeyCertificatePair = new KeyCertificatePair(TlsHelper.ObjectToPem(clientCertificate), TlsHelper.ObjectToPem(rsaKeyPair.Private));
        }
Пример #2
0
        private SslServerCredentials CreateCredentials()
        {
            var commonCertifName = "CN=" + GrpcConstants.DefaultTlsCommonName;

            // Generate the servers rsa key pair and self-signed certificate.
            var rsaKeyPair  = TlsHelper.GenerateRsaKeyPair();
            var certificate = TlsHelper.GenerateCertificate(new X509Name(commonCertifName),
                                                            new X509Name(commonCertifName), rsaKeyPair.Private, rsaKeyPair.Public);

            var keyCertificatePair = new KeyCertificatePair(TlsHelper.ObjectToPem(certificate), TlsHelper.ObjectToPem(rsaKeyPair.Private));

            return(new SslServerCredentials(new List <KeyCertificatePair> {
                keyCertificatePair
            }));
        }