2010-06-11 49 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.