你有潛力至少有兩個問題...
首先...
您的客戶端證書文件不能包含一個私鑰,除非它使用密碼進行訪問。您應該使用帶密碼的PKCS#12(* .pfx)證書,以便您的客戶端可以訪問私鑰。您打開證書時,您的客戶代碼必須提供密碼,因爲其他人已經發布。有幾種方法來創建此,最簡單的方法是使用下面的命令行,首先生成證書,然後使用MMC證書管理器導出證書私鑰:
Process p = Process.Start(
"makecert.exe",
String.Join(" ", new string[] {
"-r",// Create a self signed certificate
"-pe",// Mark generated private key as exportable
"-n", "CN=" + myHostName,// Certificate subject X500 name (eg: CN=Fred Dews)
"-b", "01/01/2000",// Start of the validity period; default to now.
"-e", "01/01/2036",// End of validity period; defaults to 2039
"-eku",// Comma separated enhanced key usage OIDs
"1.3.6.1.5.5.7.3.1," +// Server Authentication (1.3.6.1.5.5.7.3.1)
"1.3.6.1.5.5.7.3.2", // Client Authentication (1.3.6.1.5.5.7.3.2)
"-ss", "my",// Subject's certificate store name that stores the output certificate
"-sr", "LocalMachine",// Subject's certificate store location.
"-sky", "exchange",// Subject key type <signature|exchange|<integer>>.
"-sp",// Subject's CryptoAPI provider's name
"Microsoft RSA SChannel Cryptographic Provider",
"-sy", "12",// Subject's CryptoAPI provider's type
myHostName + ".cer"// [outputCertificateFile]
})
);
其次...
你的下一個問題將是服務器端。服務器必須允許此證書。您有正確的邏輯,但是在電線的錯誤一側,請將此行移至處理請求的Web服務器。如果你不能,你必須採取'。CER」文件保存以上服務器,並將其添加到服務器計算機的信任列表:
ServicePointManager.ServerCertificateValidationCallback = (a,b,c,d) => true;
你知道如何使在Windows .NET相同的工作?出於某種原因,我無法在沒有在x509商店 – galets 2014-01-31 18:23:40