Dot-Net
如何在 Windows Azure 上獲得程式碼證書
我正在嘗試創建我們自己的 WIF 身份提供程序並在 Azure 上執行它,但在嘗試自動生成聯合元數據時遇到了困難。
此行似乎不適用於 Azure:
CertificateUtil.GetCertificate(StoreName.My, StoreLocation.LocalMachine, signingCertificateName);證書已上傳到 Azure,我如何獲取它?
謝謝
試試這篇博文:http: //blogs.msdn.com/b/jnak/archive/2010/01/29/installing-certificates-in-windows-azure-vms.aspx
它建議如下程式碼:
X509Certificate2Collection selectedCerts = new X509Certificate2Collection(); X509Store store = new X509Store(StoreName.My, StoreLocation.CurrentUser); store.Open(OpenFlags.OpenExistingOnly | OpenFlags.ReadOnly); foreach (X509Certificate2 cert in store.Certificates) { // do stuff with cert }
作為其他答案的輕微變化,如果您只想獲得一個證書而不是遍歷所有證書,您可以執行以下操作:
var store = new X509Store(StoreName.My, StoreLocation.LocalMachine); store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly); X509Certificate2Collection matchedCertificates = store.Certificates.Find(X509FindType.FindBySubjectName, signingCertificateName, true); if (matchedCertificates.Count > 0) { myCertificate = matchedCertificates[0]; }(這也不是 Azure 特定的)