C# 在Azure云服务中获取x509证书

C# 在Azure云服务中获取x509证书,c#,.net,azure,x509,azure-cloud-services,C#,.net,Azure,X509,Azure Cloud Services,我需要使用证书与Azure密钥库进行身份验证,但我无法访问已上载的密钥。我已采取以下步骤: 已通过门户将密钥(.pfx)上载到云服务 将此添加到ServiceConfiguration <Certificates> <Certificate name="keyvault" thumbprint="<my_thumbprint>" thumbprintAlgorithm="sha1" /> </Certificates> 是否需要任何其他配

我需要使用证书与Azure密钥库进行身份验证,但我无法访问已上载的密钥。我已采取以下步骤:

已通过门户将密钥(.pfx)上载到云服务

将此添加到ServiceConfiguration

<Certificates>
    <Certificate name="keyvault" thumbprint="<my_thumbprint>" thumbprintAlgorithm="sha1" />
</Certificates>

是否需要任何其他配置?

出现此错误的原因是您要求Fabric Controller在一个位置安装证书

<Certificate name="keyvault" storeLocation="LocalMachine" storeName="CA" />
请确保您在这两个地方使用相同的位置

我将在
csdef
文件中进行以下更改:

<Certificate name="keyvault" storeLocation="LocalMachine" storeName="My" />

谢谢使用此配置可以在本地工作,证书是使用certmgr安装的,但部署到云服务时不能。这可能是因为您可能已经在本地计算机上读取的存储中安装了证书。请尝试通过从“CurrentUser”中的“Personal”证书存储中删除证书来运行您的代码。问题在于,我将证书本地保存在另一个存储中,而该存储是在上载到Azure后保存的。为了让它在Azure中工作,我需要像这样创建x509存储:var store=new X509Store(StoreName.CertificateAuthority,StoreLocation.LocalMachine)。如果你更新最后两行代码,我可以将你的答案标记为正确。在代码中读取证书的位置必须与csdef文件中定义的位置匹配。
Value cannot be null.
Parameter name: certificate
<Certificate name="keyvault" storeLocation="LocalMachine" storeName="CA" />
var store = new X509Store(StoreName.My, StoreLocation.CurrentUser);
<Certificate name="keyvault" storeLocation="LocalMachine" storeName="My" />
var store = new X509Store(StoreName.CertificateAuthority, StoreLocation.LocalMachine);