asp.net - 如何在 .NET Core 中使用 OpenSSL
问题描述
我在 NuGet 的 .net 核心项目中添加了一个 OpenSSL 包(System.Security.Cryptography.OpenSsl),但我不知道如何使用它。请给我一些提示。谢谢!!!
解决方案
(您需要使用 .net framework 4.7.2 或更高版本)
我正在寻找同样的东西,我发现:
// Here we define content which will be in certificate like name or state
X500DistinguishedName distinguishedName = new X500DistinguishedName("C=" + countryCode + ",ST=" + state + ",L=" + locality + ",O=" + organization + ",CN=" + fullName);
using (RSA rsa = RSA.Create()) { // create RSA key
CertificateRequest request = new CertificateRequest(distinguishedName, rsa, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
request.CertificateExtensions.Add(new X509KeyUsageExtension(X509KeyUsageFlags.DataEncipherment | X509KeyUsageFlags.KeyEncipherment | X509KeyUsageFlags.DigitalSignature, false));
request.CertificateExtensions.Add(new X509EnhancedKeyUsageExtension(new OidCollection { new Oid("1.3.6.1.5.5.7.3.1") }, false));
X509Certificate2 certificate = request.CreateSelfSigned(new DateTimeOffset(DateTime.UtcNow.AddDays(-1)), new DateTimeOffset(DateTime.UtcNow.AddDays(3650)));
// Now let's get files:
byte[] cert = certificate.Export(X509ContentType.Cert, password); //.crt
byte[] p12 = certificate.Export(X509ContentType.Pkcs12, password); //.p12
}
推荐阅读
- javascript - 如何用 postgres(pg-promise)中的当前时间戳更新空时间戳?
- android - 生成并注册一个新的上传密钥 Android React-Native
- c# - .NET 中是否有办法定期暂停线程并找出正在执行的 IL 行
- python - Django 频道创建一个单独的任务,每隔一段时间向组发送消息
- c# - 您可以更新 ContentDialog 的内容(文本)属性吗?
- python - 错误:命令引发异常:TypeError:“成员”对象不可下标
- sql - 如何在 SQL 中组合 WITH 语句和 INSERT INTO
- ios - 如果应用程序关闭,推送通知操作不会显示
- java - 是否可以为此进行循环视图?
- hive - Beeline 如何在没有有效 kerberos tgt 的情况下列出 hdfs?