I have a C++ implementation for
searching certificates base on issuer
validate those certificates
if there are more than one certificate
a. set the certificates in own store
b. show "Choose Certificate" window using CryptUIDlgSelectCertificateFromStore
return a specific value from the certificate
This is done in a Windows MFC program. Now I have to do this in a Command-Line program. I was hoping to use C# for this because it is easier to develop and you can use NUGET packages.
Is there a good and "official" C# wrapper for cryptuiapi.h
and wincrypt.h
? I found these:
https://referencesource.microsoft.com/#system/security/system/security/cryptography/cryptoapi.cs https://referencesource.microsoft.com/#WsatUI/MMCUI/MMCSafeNativeMethods.cs,95a3d8346740ba05
...but I do not like to copy code if there is better implementation (=NUGET) somewhere.
The functions that I use are:
CertOpenStore
CertCloseStore
CertEnumCertificatesInStore
CryptUIDlgSelectCertificateFromStore
CertVerifyRevocation
CertVerifyTimeValidity
CryptAcquireCertificatePrivateKey
CryptSignCertificate
CertFindCertificateInStore
CertGetIntendedKeyUsage
CertNameToStr
CertDuplicateCertificateContext
CertAddCertificateContextToStore
As I see I have 4 choices:
- Implement whole thing using c# X509Store, but I have not found a CryptUIDlgSelectCertificateFromStore for c#. I can use pinvoke but I think then I should use pinvoke for all functions.
- Implement whole thing in unmanaged C++ and use already existing code. The main project that I have is BIG and OLD so it is complicated to extract only the useful functions.
- Implement console app in C# referencing a C++ CLR Wrapper which in its turn is referencing a C++ dll with unmanaged code.
- Implement in C# and use the above pinvoke functions which can be PIA because UNICODE/ASCII problem.