如何在.NET Core中使用OpenSSL

问题描述 投票:0回答:1

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

asp.net asp.net-core openssl
1个回答
0
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.