OpenSSL.NET 无法导出带有空密码的私钥

发布于 2024-09-04 23:30:55 字数 944 浏览 5 评论 0原文

我最近发现了OpenSSL.NET,它是一个非常可爱的小包装。

我正在尝试执行以下代码:

    public static void DoSomething(byte[] buf)
    {
        OpenSSL.Core.BIO input = new OpenSSL.Core.BIO(buf);
        OpenSSL.X509.X509Certificate b = OpenSSL.X509.X509Certificate.FromPKCS12(input, "passphrase");
        OpenSSL.Core.BIO outs = OpenSSL.Core.BIO.MemoryBuffer(false);
        b.PrivateKey.WritePrivateKey(outs, OpenSSL.Crypto.Cipher.Null, "passphrase");
        outs.SetClose(OpenSSL.Core.BIO.CloseOption.Close);
        Console.WriteLine(outs.ReadString());
    }

问题出现在“b.PrivateKey.WritePrivateKey(..”行。我想在不进行任何加密的情况下写出私钥。根据规范,如果我使用空密码,请输入以下内容应该可以解决问题,但无论我在 buf 中使用什么证书,它都不会起作用。

这是例外:

错误:0D0A706C:asn1 编码例程:PKCS5_pbe2_set:密码没有对象标识符。 错误:2307D00D:PKCS12 例程:PKCS8_加密:ASN1 lib

我知道这部分工作正常,因为如果我指定任何其他密码类型,它会导出私钥而不会失败。有人有什么建议吗?

I've recently discovered OpenSSL.NET and it's a pretty sweet little wrapper.

I'm trying to execute the following code:

    public static void DoSomething(byte[] buf)
    {
        OpenSSL.Core.BIO input = new OpenSSL.Core.BIO(buf);
        OpenSSL.X509.X509Certificate b = OpenSSL.X509.X509Certificate.FromPKCS12(input, "passphrase");
        OpenSSL.Core.BIO outs = OpenSSL.Core.BIO.MemoryBuffer(false);
        b.PrivateKey.WritePrivateKey(outs, OpenSSL.Crypto.Cipher.Null, "passphrase");
        outs.SetClose(OpenSSL.Core.BIO.CloseOption.Close);
        Console.WriteLine(outs.ReadString());
    }

Problem comes at the "b.PrivateKey.WritePrivateKey(.." line. I want to write the private key out without any encryption. According to spec, if I use a Null cipher type this should do the trick, but it never works, regardless of the cert I use in buf.

Here's the exception:

error:0D0A706C:asn1 encoding routines:PKCS5_pbe2_set:cipher has no object identifier
error:2307D00D:PKCS12 routines:PKCS8_encrypt:ASN1 lib

I know this part works fine because if I specify any other cipher type, it exports the private key without fail. Anyone have any suggestions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

南城旧梦 2024-09-11 23:30:56

为什么你不能使用:

    OpenSSL.Core.BIO outs = OpenSSL.Core.BIO.MemoryBuffer(false);
    outs.Write(b.PrivateKey.ToString());
    outs.SetClose(OpenSSL.Core.BIO.CloseOption.Close);
    Console.WriteLine(outs.ReadString());

这样你就可以编写未加密的密钥。

我明白了,将其更改为:

    OpenSSL.Core.BIO outs = OpenSSL.Core.BIO.MemoryBuffer(false);
    outs.Write(b.PrivateKey.GetRSA().PrivateKeyAsPEM);
    outs.SetClose(OpenSSL.Core.BIO.CloseOption.Close);
    Console.WriteLine(outs.ReadString());

Why can't you use:

    OpenSSL.Core.BIO outs = OpenSSL.Core.BIO.MemoryBuffer(false);
    outs.Write(b.PrivateKey.ToString());
    outs.SetClose(OpenSSL.Core.BIO.CloseOption.Close);
    Console.WriteLine(outs.ReadString());

this way you can write unencrypted keys.

I see, change that to:

    OpenSSL.Core.BIO outs = OpenSSL.Core.BIO.MemoryBuffer(false);
    outs.Write(b.PrivateKey.GetRSA().PrivateKeyAsPEM);
    outs.SetClose(OpenSSL.Core.BIO.CloseOption.Close);
    Console.WriteLine(outs.ReadString());
偏爱你一生 2024-09-11 23:30:56

我并没有真正使用它,但也许这可能会有所帮助:

如果正在编译 OpenSSL
SSL 将在其中开发系统
在协议级别进行调试,
省略命令
-DSSL_FORBID_ENULL 是可接受的。 -DSSL_FORBID_ENULL 导致 OpenSSL 忽略 SSL 密码中的空密码
套房。空密码允许明文
(未加密的信息)要遍历
电线。空密码不提供
保密且不被鼓励
用于生产系统。

I don't really use that but perhaps this may help:

If OpenSSL is being compiled for a
development system in which SSL will
be debugged at the protocol level,
omitting the command
-DSSL_FORBID_ENULLis acceptable. -DSSL_FORBID_ENULL causes OpenSSL to omit null ciphers in the SSL cipher
suite. Null ciphers permit cleartext
(unencrypted information) to traverse
the wire. Null ciphers provide no
confidentiality and aren't encouraged
for use on production systems.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文