使用CryptUIWizImport自动导入证书作为C++的受信任根
import a certificate using CryptUIWizImport automatically as a trusted root with C++
我使用以下代码将证书作为受信任的根导入:
#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%xn”, GetLastError());
}
return 0;
}
但是,这种方法将我的证书作为Intermediate Certificate Authorities
导入,而我需要将其作为Trusted Root Certificate Authorities
导入。我不想使用任何向导方法,也不能更改我的证书。
是否可以将此证书作为受信任的根导入?
CryptUIWizImport
中是否有任何属性可以将证书类型设置为受信任的根?
感谢预付款
我们应该从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
文件旁边。
相关文章:
- 我可以信任表示整数的浮点或双精度来保持精度吗
- CertGetCertificateChain 具有支持的内存存储和证书信任列表
- 从网站复制证书,并使用脚本将其添加到受信任的根证书颁发机构
- 在抛出异常后,我可以信任 vector::size 吗?
- 我们可以信任编译器优化多少
- 仅从受信任的库执行功能
- 证书链的根证书是自签名和不信任的
- 在 C++/STL/MFC 应用程序启动早期发生的致命异常中,是否可以信任堆栈回溯符号名称?
- 用于信任区域反射算法的库
- 验证本地计算机的活动目录域信任关系
- SSL_CTX_load_verify_locations和受信任的证书
- 使用CryptUIWizImport自动导入证书作为C++的受信任根
- QSsl错误:证书是自签名的,不受信任
- 验证进程外的COM服务器客户端是否受信任
- 在带有OpenSSL的Windows上使用受信任证书
- 如何使用CryptoAPI在windows7上获取证书信任列表
- 这是openMP的正确用法吗?(或者:我可以信任默认设置吗?)
- 可以在中等信任环境中运行c++ dll
- OpenSSL区分受信任CA证书和自签名CA证书
- 添加x509v3扩展会导致Mozilla pkix不信任