看過如何從Creating a self-signed certificate in C#生成自簽名數字簽名後,我可以調用CreateSelfSignCertificatePfx並將字節數組中的PXF數據返回,然後可以在X509Certificate2對象內使用它來簽名並驗證。示例...帶密碼安全的PFX自簽名x509證書
byte[] pfx = Certificate.CreateSelfSignCertificatePfx("O=Company,CN=Firstname,SN=Lastname", DateTime.Now, DateTime.Now.AddYears(1), "password");
X509Certificate2 cert = new X509Certificate2(pfx, "password");
byte[] publicBytes = cert.RawData;
RSACryptoServiceProvider rsa = (RSACryptoServiceProvider)cert.PrivateKey;
byte[] signedData = rsa.SignData(new System.Text.UTF8Encoding().GetBytes("Test"), new SHA1CryptoServiceProvider());
RSACryptoServiceProvider rsa2 = (RSACryptoServiceProvider)new X509Certificate2(publicBytes).PublicKey.Key;
bool verified = rsa2.VerifyData(new System.Text.UTF8Encoding().GetBytes("Test"), new SHA1CryptoServiceProvider(), signedData);
This works。我的關注點雖然是來自上面的原始字節byte [] pfx需要存儲在一個數據庫中(用來簽名)。問題在於,這種格式的字節有多安全?我知道你需要密碼才能用私鑰構造新的X509Certificate2,但從一般意義上講,沒有密碼的字節有多安全?我沒有問題將這些字節作爲附加層加密,但這是必要的嗎?
根據X509Certificate2.X509Certificate2(Byte[], String) Constructor
調用此構造函數使用正確的密碼解密私鑰並將其保存到一個關鍵的容器。
我只是想確保沒有密碼的私鑰是安全的。
我很抱歉遲到的回覆,假期和所有。問題是僅憑密碼的X509證書有多安全?如果你有密碼,你有私鑰,但沒有密碼,私鑰有多安全? – user1097974 2011-12-27 14:30:55