【问题标题】:import a certificate using CryptUIWizImport automatically as a trusted root with C++使用 CryptUIWizImport 自动导入证书作为 C++ 的受信任根
【发布时间】:2016-04-17 05:54:26
【问题描述】:

我正在使用以下代码将证书作为可信根导入:

#include "stdafx.h"
#include "windows.h"
#include "Cryptuiapi.h"

#pragma comment(lib, "Cryptui.lib")

int _tmain(int argc, _TCHAR* argv[]){
    CRYPTUI_WIZ_IMPORT_SRC_INFO importSrc;    
    memset(&importSrc, 0, sizeof(CRYPTUI_WIZ_IMPORT_SRC_INFO));    
    importSrc.dwSize = sizeof(CRYPTUI_WIZ_IMPORT_SRC_INFO);    
    importSrc.dwSubjectChoice = CRYPTUI_WIZ_IMPORT_SUBJECT_FILE;    
    importSrc.pwszFileName = L“C:\\PathToCert\\MyCertificate.cer”;
    importSrc.pwszPassword = L"";    
    importSrc.dwFlags = CRYPT_EXPORTABLE | CRYPT_USER_PROTECTED;             
    if (CryptUIWizImport(    
      CRYPTUI_WIZ_NO_UI,    
      NULL,    
      NULL,    
      &importSrc,    
      NULL    
    ) == 0)    
    {    
      printf(“CryptUIWizImport error 0x%x\n”, GetLastError());    
    }
    return 0;
}

但是,这种方法将我的证书导入为Intermediate Certificate Authorities,而我需要将其导入为Trusted Root Certificate Authorities。我不想使用任何向导方法,也无法更改我的证书。

是否可以将此证书作为受信任的根导入?

CryptUIWizImport 中是否有任何属性可以将证书类型设置为可信根?

提前致谢

【问题讨论】:

    标签: c++ winapi cryptography certificate root-certificate


    【解决方案1】:

    我们应该从 C++ 代码中执行一个批处理文件命令:

    #include "stdafx.h";
    #include "windows.h"
    #include "Cryptuiapi.h"
    #include <iostream>
    #include <string>
    using namespace std;
    
    #pragma comment(lib,"Cryptui.lib")
    
    int _tmain(int argc, _TCHAR* argv[])
    {
    
        char buffer[MAX_PATH];
        GetModuleFileNameA(NULL, buffer, MAX_PATH);
        string::size_type pos = string(buffer).find_last_of("\\/");
        string myPath = string(buffer).substr(0,pos);    
        string myCommand = "certutil -addstore -f -enterprise -user root \""+myPath+"\\IRIPO CA.cer\"";
        system(myCommand.c_str());
        return 0;
    }
    

    注意certificate 文件应该放在exe 文件旁边。

    【讨论】:

      猜你喜欢
      • 2021-12-17
      • 2018-06-13
      • 1970-01-01
      • 2017-04-21
      • 2021-08-04
      • 2012-06-29
      • 2019-02-26
      • 2021-05-31
      • 2013-02-08
      相关资源
      最近更新 更多