首页 > 解决方案 > 如何在 .NET Core 中使用 OpenSSL

问题描述

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

标签: asp.netasp.net-coreopenssl

解决方案


(您需要使用 .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


推荐阅读