简体   繁体   English

如何从应用程序的证书库中删除证书?

[英]How can I remove a certificate from my app's certificate store?

I've got Windows Store/Phone universal app that will have to store certificates. 我有Windows Store / Phone通用应用程序,必须存储证书。 I have no trouble loading the certificates into the app's CertificateStore, and using them. 我可以将证书加载到应用程序的CertificateStore中并使用它们。 But when it comes to deleting them I have trouble. 但是当涉及到删除它们时,我遇到了麻烦。

For example, the following code works great to find my certificate in the Windows Store environment: 例如,以下代码非常适合在Windows应用商店环境中查找我的证书:

async Task<Certificate> FindMyCert()
{
    var query = new CertificateQuery();
    query.FriendlyName = "mytestcert";
    var certificates = await CertificateStores.FindAllAsync(query);

    if (certificates.Count != 1)
    {
        return null;
    }
    return certificates[0];
}

Now, lets say I want to remove that certificate from the store. 现在,假设我想从商店中删除该证书。 The only "Delete" I know about is on the CertificateStore object. 我所知道的唯一“删除”是在CertificateStore对象上。 So I need to fetch the certificate store and then do the delete: 所以我需要获取证书存储区然后执行删除操作:

var s = CertificateStores.GetStoreByName("MY");
if (s != null)
    s.Delete(c);
Assert.IsNull(await FindMyCert());

There is only one problem. 只有一个问题。 If you look at the documentation for GetStoreName 1 , however, it says that the name of the certificate store can't be "MY". 但是,如果您查看GetStoreName 1的文档,则表明证书存储的名称不能是“MY”。

The irony is this works sometimes and other times it doesn't work. 具有讽刺意味的是,这有时会起作用,有时却无效。 I would guess there is an accepted way to do something like remove a cert from the store. 我猜有一种可以接受的方法来做一些事情,比如从商店中删除证书。 But I have not been able to figure it out. 但我无法弄明白。

Many thanks in advance! 提前谢谢了!

We were facing the same problem recently and opened a support ticket on that case. 我们最近遇到了同样的问题,并在那个案子上开了一张支持票。 According to MS, this is not possible in Windows Phone 8.1, I'm sorry. 根据MS,这在Windows Phone 8.1中是不可能的,对不起。 It should be supported in Windows 10 though. 但它应该在Windows 10中受支持。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM