Saving/Restoring certs with MS CryptoAPI invalidates attached private key

天涯浪子 提交于 2019-11-30 17:04:23

You use wrong CryptoAPI. You should use PFXExportCertStoreEx and PFXImportCertStore instead.

UPDATED: The functions are very common. You can not export certificates from the SmartCard of course or other non-exportable certificates. The BLOG in the function is nothing more as the contain of the PFX file. For example the import of the certificate from PFX file should do the following:

  1. Open the PFX file and read full contain in the memory. You can use of course the file mapping instead.
  2. Optionally you can use PFXIsPFXBlob function to verify that the file has really contain which corresponds to the PFX file.
  3. You use PFXImportCertStore to open the BLOB (the PFX) as the source certificate store.
  4. You use CertOpenStore or some other function to open the destination certificate store where you want save the certificates from the PFX file.
  5. You use CertEnumCertificatesInStore to enumerate certificates from the source certificate store (PFX) and for all certificate use CertAddCertificateContextToStore to add certificate from the source certificate store to the destination certificate store. The certificates having private key will be imported with the private key.
  6. You use CertCloseStore to close both opened stores.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!