2010-06-11 52 views
1

我最近发现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_encrypt:ASN1 lib

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

回答

1

你为什么不能使用:

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()); 
+0

PrivateKey.ToString()创建一个ASCII私钥(人类可读的)表示。确实存在所有的数据,但我正在寻找RAW/Unencrypted二进制私钥数据。 – Nick 2010-06-21 17:22:53

+0

你的第二个评论的作品!指向你! – Nick 2010-06-21 19:07:34

0

我真的不使用,但也许这可以帮助:

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.