Автор: Максим Коллегин 
Пароль в юникод? Сможете выложить законченный пример кода?
#include <iostream>
#include <Windows.h>
#include <wincrypt.h>
#include <vector>
#include <string>
using namespace std;
int ImportPFX(string xFilePath, wstring xPassword) {
HANDLE hfile = INVALID_HANDLE_VALUE;
HANDLE hsection = 0;
void* pfx = 0;
HCERTSTORE pfxStore = 0;
HCERTSTORE hFileStore = 0;
HCERTSTORE myStore = 0;
PCCERT_CONTEXT pctx = 0;
hfile = CreateFileA(xFilePath.c_str(), FILE_READ_DATA, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0);
CRYPT_DATA_BLOB blob;
blob.cbData = GetFileSize(hfile, 0);
BYTE *fb = (BYTE*)malloc(blob.cbData * sizeof(BYTE));
DWORD dw = 0;
BOOL b1 = ReadFile(hfile, fb, blob.cbData, &dw, NULL);
cout << "b1 = " << b1 << endl;
blob.pbData = (BYTE*)fb;
BOOL b2 = PFXIsPFXBlob(&blob);
cout << "b2 = " << b2 << endl;
//pfxStore = PFXImportCertStore(&blob, xPassword.c_str(), CRYPT_EXPORTABLE | PKCS12_IMPORT_SILENT);
//pfxStore = PFXImportCertStore(&blob, xPassword.c_str(), CRYPT_EXPORTABLE);
pfxStore = PFXImportCertStore(&blob, xPassword.c_str(), PKCS12_IMPORT_SILENT);
if (!pfxStore) cout << "Error in PFXImportCertStore" << endl;
cout << "GetLastError = " << GetLastError() << endl;
cout << "pfxStore = " << pfxStore << endl;
myStore = CertOpenStore(CERT_STORE_PROV_SYSTEM, 0, 0, CERT_STORE_OPEN_EXISTING_FLAG | CERT_SYSTEM_STORE_CURRENT_USER, L"MY");
if (!myStore) cout << "Error in 'CertOpenSystemStore'" << endl;
while (0 != (pctx = CertEnumCertificatesInStore(pfxStore, pctx))) {
char name[128];
if (!CertGetNameStringA(pctx, CERT_NAME_FRIENDLY_DISPLAY_TYPE, 0, 0, name, sizeof name / sizeof *name)) cout << "Error in 'CertGetNameString'" << endl;
cout << "name = " << name << endl;
if (!CertAddCertificateContextToStore(myStore, pctx, CERT_STORE_ADD_REPLACE_EXISTING, 0)) {
DWORD err = GetLastError();
// Maybe theres another equal certificate already added
if (CRYPT_E_EXISTS == err) {
if (!CertAddCertificateContextToStore(myStore, pctx, CERT_STORE_ADD_REPLACE_EXISTING, 0)) cout << "Error in 'CertAddCertificateContextToStore'" << endl;
}else{
cout << "Error en 'CertAddCertificateContextToStore'" << endl;
}
}
}
return 1;
}
int main() {
ImportPFX("c:\\test\\Test_Token_5.pfx", L"1qwe");
cout << "Done" << endl;
getchar();
}