代码之家  ›  专栏  ›  技术社区  ›  Pratap Bhaskar

将证书作为嵌入资源加载到程序集中

  •  3
  • Pratap Bhaskar  · 技术社区  · 9 年前

    我在程序集中添加了一个PFX文件作为嵌入资源,以使用证书对JWT令牌进行签名。我将pfx作为流加载,读取所有字节,并使用X509Certificate2加载私钥

    公共X509Certificate2(字节[]rawData,字符串密码)

    非常感谢您的帮助。 谢谢

    1 回复  |  直到 9 年前
        1
  •  4
  •   Fei Han    9 年前

    似乎你想从Azure app Service web app上的应用程序访问证书,你可以将你的证书上载到Azure网站中的证书集合,并从你的网站个人证书存储在你的web应用程序中使用它。

    enter image description here 添加名为WEBSITE\u LOAD\u CERTIFICATES的应用程序设置,其值设置为证书的指纹

    enter image description here

    使用申请中的证书

    X509Certificate2 retVal = null;
    
    X509Store certStore = new X509Store(StoreName.My, StoreLocation.CurrentUser);
    certStore.Open(OpenFlags.ReadOnly);
    
    X509Certificate2Collection certCollection = certStore.Certificates.Find(X509FindType.FindByThumbprint, thumbprint, false);
    
    if (certCollection.Count > 0)
    {
        retVal = certCollection[0];
    }
    
    certStore.Close();
    

    Using Certificates in Azure Websites Applications