提问
https证书如何导入
回答
- C#生成自签名证书
var rsa = RSA.Create();
var x500Name = new X500DistinguishedName("CN=[通用名], O=[公司], OU=[单位]" );
var req = new CertificateRequest(x500Name, rsa, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
var sanBuilder = new SubjectAlternativeNameBuilder();
sanBuilder.AddDnsName("localhost");
sanBuilder.AddDnsName(Environment.MachineName);
sanBuilder.AddIpAddress(IPAddress.Parse("127.0.0.1"));
sanBuilder.AddIpAddress(IPAddress.Parse("::1"));
req.CertificateExtensions.Add(sanBuilder.Build());
var cert = req.CreateSelfSigned(DateTimeOffset.Now, DateTimeOffset.Now.AddYears(10));
File.WriteAllBytes($@"{AppDomain.CurrentDomain.BaseDirectory}\self.pfx", cert.Export(X509ContentType.Pfx, "111111"));
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*",
"Kestrel": {
"Endpoints": {
"MyHttpsEndpoint": {
"Url": "https://localhost:5001",
"SslProtocols": [ "Tls12", "Tls13" ],
"Certificate": {
"Path": "self.pfx",
"Password": "111111"
}
}
}
}
}
标签:sanBuilder,证书,req,导入,https,var,new
From: https://www.cnblogs.com/wuhailong/p/17412495.html