How would I generate the Identity Server signing certificate

后端 未结 4 1995
灰色年华
灰色年华 2021-01-31 05:00

In the identity server samples we find code like this in Startup.cs

var certFile = env.ApplicationBasePath + \"\\\\idsrv3test.pfx\";

var signingCer         


        
4条回答
  •  庸人自扰
    2021-01-31 05:47

    For the record, the code proposed in the image posted by RuSs:

    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];
        }
    }
    

提交回复
热议问题