I am new to the site so please correct me if I do something wrong.
I have been trying to digitally sign PDF documents from a smart card (never tried or done it before). So far I haven't had much luck but I've tried exporting the certificates from my smart card and use them that way. Problem is on the smart card, there are 2 separate certificates where one of them is used for authentication and has a private key and the other is almost the same only without the key. My goal is to build an application that will sign pdf files in batches. I am completely lost on this one so I would really appreciate some help
I tried implementing this but had no luck so far. Adding a Digital signature to a PDF with iTextSharp
Also tried this example but the pfx file I get from exporting the certificate is invalid somehow E-signing PDF documents with iTextSharp
Edit: The code I am currently trying to use is from this answer. The error I am getting is "Invalid flags specified". Below is a command line export from the command CertUtil -ScInfo
================ Certificate 1 ================
--- Reader: Generic EMV Smartcard Reader 0
--- Card: SmartCafe Expert v7.0 with NetSeT PKI
Provider = Microsoft Base Smart Card Crypto Provider
Key Container = ed70b1d1fbcb443ab1bb3bb40******
Serial Number: *********
Issuer: CN=********, O=********, OU=********, OID********, L=********, C=********
NotBefore: 10.05.2022 07:42
NotAfter: 10.05.2027 07:42
Subject: CN=******** ******** Sign, G=********, SN=********, SERIALNUMBER=CA:********, SERIALNUMBER=********, C=********
Non-root Certificate
Cert Hash(sha1): e30749b119fba55f6a8242d72d7e5e********
Performing AT_SIGNATURE public key matching test...
Public key matching test succeeded
Key Container = ed70b1d1fbcb443ab1bb3bb40******
Provider = Microsoft Base Smart Card Crypto Provider
ProviderType = 1
Flags = 1
0x1 (1)
KeySpec = 2 -- AT_SIGNATURE
Private key verifies
Performing cert chain verification...
Chain validates
Smart Card Logon: Chain validates
dwFlags = CA_VERIFY_FLAGS_NT_AUTH (0x10)
dwFlags = CA_VERIFY_FLAGS_CONSOLE_TRACE (0x20000000)
dwFlags = CA_VERIFY_FLAGS_DUMP_CHAIN (0x40000000)
Application[0] = 1.3.6.1.4.1.311.20.2.2 Smart Card Logon
ChainFlags = CERT_CHAIN_REVOCATION_CHECK_CHAIN_EXCLUDE_ROOT (0x40000000)
HCCE_LOCAL_MACHINE
CERT_CHAIN_POLICY_NT_AUTH
-------- CERT_CHAIN_CONTEXT --------
ChainContext.dwInfoStatus = CERT_TRUST_HAS_PREFERRED_ISSUER (0x100)
ChainContext.dwRevocationFreshnessTime: 167 Days, 1 Minutes, 7 Seconds
SimpleChain.dwInfoStatus = CERT_TRUST_HAS_PREFERRED_ISSUER (0x100)
SimpleChain.dwRevocationFreshnessTime: 167 Days, 1 Minutes, 7 Seconds
I am using the following input parameters in the app:
ProviderName="Microsoft Base Smart Card Crypto Provider"
KeyContainerName = "ed70b1d1fbcb443ab1bb3bb40******"