尝试使用从 CurrentUser Store 检索到的证书私钥时出错

泥浆

我正在尝试使用我的证书代理证书签署 CSR。但是,当我从 currentUser 的商店获取证书并尝试使用密钥对其进行签名时,我收到此错误“CertEnroll::CSignerCertificate::Initialize:找不到对象或属性。0x80092004 (-2146885628 CRYPT_E_NOT_FOUND)”但是如果我得到它来自 LocalMachine Store 我没有这个问题,它可以工作。我无法使用本地机器来存储证书,因为证书代理证书的私钥不可导出。

这是我从 cert sotre 获取证书的代码:

        const string ekuOid = "2.5.29.37";
        const string enrollmentAgentOid = "1.3.6.1.4.1.311.20.2.1";
        var store = new X509Store("MY", StoreLocation.CurrentUser);
        store.Open(OpenFlags.ReadOnly);
        X509Certificate2 certificate = null;
        foreach (var cert in store.Certificates)
        {
            if (!cert.HasPrivateKey || cert.NotBefore > DateTime.UtcNow || DateTime.UtcNow > cert.NotAfter) { continue; }
            foreach (var eku in cert.Extensions.Cast<X509Extension>().Where(ext => ext.Oid.Value == ekuOid).Cast<X509EnhancedKeyUsageExtension>())
            {
                if (eku.EnhancedKeyUsages.Cast<Oid>().Any(usage => usage.Value == enrollmentAgentOid))
                {
                    certificate = cert;
                }
            }
        }
        return certificate;

但是当我调用 CERTENROLLLib 初始值设定项(Initialize(bool MachineContext, X509PrivateKeyVerify VerifyType, EncodingType Encoding, string strCertificate))时,我得到了上面提到的异常。查看调试器时,变量看起来与来自 LocalMachine 时相同来自当前用户。

泥浆

问题出在初始化中,我将机器上下文设置为 true 而不是 false 使其失败。证书在调试器工具显示时被正确检索。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

尝试在CurrentUser的React DOM上反映CurrentUser的Redux状态更改?

Azure应用服务:在X509Store(StoreName.My,StoreLocation.CurrentUser)中找不到证书

获取 currentuser 子项时出错,firebase

无法在加载时获取currentUser

尝试使用 selenium 检索文本时出错

尝试使用python导入ECC私钥时出错

如何使用Vue.js,AWS Amplify和MongoDB检索currentUser数据

在IIS CurrentUser /个人存储中安装证书

错误:没有商店的提供者!在使用Angular 4.0尝试@ ngrx / store时

在 Flutter 上使用 FirebaseAuth.currentUser.getIdToken() 生成的 Firebase IdToken 在 Go 后端给出错误“无法验证令牌签名”

尝试使用ExecuteScalar <object>从表中检索数据时出错?

尝试检索BusinessPartnerUUID时出错

尝试使用 ValueListenableBuilder 时出错

尝试使用pubnub时出错

尝试使用堆时出错

尝试使用 WSL SSH 到服务器时出错

如果不建议使用currentUser(),该如何使用.then?

使用async / await获取firebase.auth()。currentUser

使用Firebase 3和Swift注销用户仍然显示`currentUser`

使用流星的currentUser助手进行链接的条件

PFUser currentUser在使用Parse SDK登录Facebook后返回nil

在Rails 4中使用session_store时出错

在Windows Store App中使用WebView控件时出错

页面刷新时,firebase.auth()。currentUser返回null

当用户注销时,{{#if currentUser}}的内部图标仍然呈现

尝试从数据库检索时出错

尝试在Android中将图像保存并检索到数据库时出错

尝试使用 c# 和 x509 删除证书时出错

流星currentUser