【问题标题】:How to use OpenSSL in.NET Core如何在 .NET Core 中使用 OpenSSL
【发布时间】:2021-08-28 04:23:56
【问题描述】:

我在 NuGet 中的 .net 核心项目中添加了一个 OpenSSL 包(System.Security.Cryptography.OpenSsl),但我不知道如何使用它。请给我一些提示。谢谢!!!

【问题讨论】:

标签: asp.net asp.net-core openssl


【解决方案1】:

(您需要在 .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
}

来源:https://stackoverflow.com/a/50138133/10952503

【讨论】:

    猜你喜欢
    • 2016-11-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-21
    • 2017-05-01
    • 1970-01-01
    相关资源
    最近更新 更多