Created
June 5, 2023 09:48
-
-
Save bjoerntx/b02de6a85c73a93f69b877f991b75536 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static X509Certificate2 RetrieveCertificate() { | |
// get and open certificate store for current user | |
X509Store store = new X509Store(StoreLocation.CurrentUser); | |
store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly); | |
// retrieve the certificate using the integrated Windows UI | |
X509Certificate2Collection selectedCertificates = | |
X509Certificate2UI.SelectFromCollection( | |
store.Certificates, | |
"Choose your certificate", | |
"Please select a certificate that is used to sign the PDF.", | |
X509SelectionFlag.SingleSelection); | |
// return the first selected certificate with a private key | |
foreach (var certificate in selectedCertificates) { | |
if (certificate.HasPrivateKey) | |
return certificate; | |
} | |
return null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment