OpenSSL.NET 无法导出带有空密码的私钥
我最近发现了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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为什么你不能使用:
这样你就可以编写未加密的密钥。
我明白了,将其更改为:
Why can't you use:
this way you can write unencrypted keys.
I see, change that to:
我并没有真正使用它,但也许这可能会有所帮助:
I don't really use that but perhaps this may help: