【问题标题】:ASP.Net Fw 4.0 CertEnroll API The system cannot find the file specifiedASP.Net Fw 4.0 CertEnroll API 系统找不到指定的文件
【发布时间】:2016-02-08 06:28:42
【问题描述】:

在 Asp.net fw 4 网站上使用 CertEnroll dll 实施证书:

    CX509CertificateRequestPkcs10 objPkcs10 = new CX509CertificateRequestPkcs10Class();
    CX509PrivateKey objPrivateKey = new CX509PrivateKeyClass();
    CCspInformation objCSP = new CCspInformationClass();
    CCspInformations objCSPs = new CCspInformationsClass();
    CX500DistinguishedName objDN = new CX500DistinguishedNameClass();
    CX509Enrollment objEnroll = new CX509EnrollmentClass();
    CObjectIds objObjectIds = new CObjectIdsClass();
    CObjectId objObjectId = new CObjectIdClass();
    CX509ExtensionKeyUsage objExtensionKeyUsage = new CX509ExtensionKeyUsageClass();
    CX509ExtensionEnhancedKeyUsage objX509ExtensionEnhancedKeyUsage = new CX509ExtensionEnhancedKeyUsageClass();
    string strRequest;


    try
    {

        //  Initialize the csp object using the desired Cryptograhic Service Provider (CSP)
        objCSP.InitializeFromName(
            "Microsoft Enhanced Cryptographic Provider v1.0"
        );
        //  Add this CSP object to the CSP collection object
        objCSPs.Add(
            objCSP
        );
        //  Provide key container name, key length and key spec to the private key object
        //objPrivateKey.ContainerName = "AlejaCMa";
        objPrivateKey.Length = 1024;
        objPrivateKey.KeySpec = X509KeySpec.XCN_AT_SIGNATURE;
        objPrivateKey.KeyUsage = X509PrivateKeyUsageFlags.XCN_NCRYPT_ALLOW_ALL_USAGES;
        objPrivateKey.MachineContext = false;


        //  Provide the CSP collection object (in this case containing only 1 CSP object)
        //  to the private key object
        objPrivateKey.CspInformations = objCSPs;

        //  Create the actual key pair
        objPrivateKey.Create();
......

它抛出以下错误消息(在最后一行)

Certificate Error CertEnroll::CX509PrivateKey::Create: The system cannot find the file specified. 0x80070002 (WIN32: 2 ERROR_FILE_NOT_FOUND) 

调试时它通过指令 Create() 没有错误...但在我的测试环境中:Windows Server 2012 它失败了

来源:http://blogs.msdn.com/b/alejacma/archive/2008/09/05/how-to-create-a-certificate-request-with-certenroll-and-net-c.aspx

【问题讨论】:

标签: c# asp.net .net-4.0 certificate certenroll


【解决方案1】:

我通过在 IIS 高级设置中设置 Load User Profile = True 解决了这个问题

Tim Erikson 回复here

【讨论】:

    猜你喜欢
    • 2017-05-05
    • 2010-11-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-21
    • 2023-03-17
    • 2017-12-21
    相关资源
    最近更新 更多