在身份服務器樣本,我們發現在Startup.cs
我怎麼會產生Identity Server的簽名證書
var certFile = env.ApplicationBasePath + "\\idsrv3test.pfx";
var signingCertificate = new X509Certificate2(certFile, "idsrv3test");
我怎麼會去更換這對於生產場景這樣的代碼?
在身份服務器樣本,我們發現在Startup.cs
我怎麼會產生Identity Server的簽名證書
var certFile = env.ApplicationBasePath + "\\idsrv3test.pfx";
var signingCertificate = new X509Certificate2(certFile, "idsrv3test");
我怎麼會去更換這對於生產場景這樣的代碼?
獲得一個專用的證書 - 無論是通過您的PKI或自生成一個:
http://brockallen.com/2015/06/01/makecert-and-creating-ssl-or-signing-certificates/
進口的關鍵配對到Windows證書存儲區,並在運行時從那裏加載它。
爲了加強安全性,有些人將密鑰部署到專用設備(稱爲HSM)或專用機器(例如防火牆後面)。 ITokenSigningService
允許將實際的令牌簽名移動到該單獨的機器。
這裏是我在我的配置從指紋加載: Click here to see image
根據記錄,該代碼張貼拉斯圖像中提出:
options.SigningCertificate = LoadCertificate();
public X509Certificate2 LoadCertificate()
{
string thumbPrint = "104A19DB7AEA7B438F553461D8155C65BBD6E2C0";
// Starting with the .NET Framework 4.6, X509Store implements IDisposable.
// On older .NET, store.Close should be called.
using (var store = new X509Store(StoreName.My, StoreLocation.LocalMachine))
{
store.Open(OpenFlags.ReadOnly);
var certCollection = store.Certificates.Find(X509FindType.FindByThumbprint, thumbPrint, validOnly: false);
if (certCollection.Count == 0)
throw new Exception("No certificate found containing the specified thumbprint.");
return certCollection[0];
}
}
最近我決定重整我的令牌簽名發放過程。如果您運行的是Windows 10,則可以使用名爲New-SelfSignedCertificate的awesome powershell cmdlet。
這是我的使用例子:
New-SelfSignedCertificate -Type Custom
-Subject "CN=TokenSigningForIdServer"
-TextExtension @("2.5.29.37={text}1.3.6.1.5.5.7.3.3")
-KeyUsage DigitalSignature
-KeyAlgorithm RSA
-KeyLength 2048
-CertStoreLocation "Cert:\LocalMachine\My"
請確保您作爲管理員運行命令。您可以通過打開certlm.msc來獲取證書詳細信息。它應該存儲在Personal \ Certificates下面。
除了-TextExtention之外,大多數標誌都應該是顯而易見的。它指定Enhaced Key Usage字段設置爲「代碼簽名」值。您可以使用所使用的算法,密鑰長度,甚至通過參考以下documentation頁面添加擴展。
in .NET 4.6'X509Store'實現'IDisposable',所以不需要'store.Close()'。更多細節在這裏http://stackoverflow.com/questions/18475558/what-is-the-implication-of-not-using-x509store-close-method – Kuncevic
@Kuncevic:謝謝,我更新了示例。 –