77{
88 // Get the PDF form
99 PdfLoadedForm form = document . Form ;
10-
1110 if ( form != null && form . Fields != null && form . Fields . Count > 0 )
1211 {
1312 foreach ( PdfLoadedField field in form . Fields )
1413 {
1514 // Check for signature field
1615 if ( field is PdfLoadedSignatureField signatureField && signatureField . IsSigned )
1716 {
17+ Console . WriteLine ( $ "Signature Field: { signatureField . Name } ") ;
1818 // Validate signature
1919 PdfSignatureValidationResult result = signatureField . ValidateSignature ( ) ;
20-
2120 if ( result ? . Certificates != null && result . Certificates . Count > 0 )
2221 {
2322 X509Certificate2 certificate = result . Certificates [ 0 ] ;
24-
23+ Console . WriteLine ( "Issuer: " + certificate . Issuer ) ;
24+ Console . WriteLine ( "Subject: " + certificate . Subject ) ;
2525 string policyId = GetCertificatePolicyOID ( certificate ) ;
2626
2727 if ( ! string . IsNullOrEmpty ( policyId ) )
2828 {
2929 Console . WriteLine ( $ "Policy OID: { policyId } ") ;
30-
31- string certClass = MapCertificateClass ( policyId ) ;
32- Console . WriteLine ( $ "Certificate Type: { certClass } ") ;
3330 }
3431 else
3532 {
3633 Console . WriteLine ( "❌ Certificate policy not found." ) ;
3734 }
38-
3935 Console . WriteLine ( "-----------------------------------" ) ;
4036 }
4137 }
@@ -51,7 +47,6 @@ string GetCertificatePolicyOID(X509Certificate2 certificate)
5147 if ( extension ? . Oid ? . Value == "2.5.29.32" )
5248 {
5349 string formatted = extension . Format ( true ) ;
54-
5550 // Example format contains: "Policy Identifier=OID"
5651 return ExtractPolicyID ( formatted ) ;
5752 }
@@ -83,39 +78,14 @@ string CleanOID(string oid)
8378{
8479 if ( string . IsNullOrEmpty ( oid ) )
8580 return null ;
86-
8781 // Remove line breaks, tabs, spaces
8882 oid = oid . Replace ( "\r " , "" )
8983 . Replace ( "\n " , "" )
9084 . Replace ( "\t " , "" )
9185 . Trim ( ) ;
92-
9386 // Remove anything after invalid characters like '['
9487 int index = oid . IndexOfAny ( new char [ ] { '[' , ' ' } ) ;
9588 if ( index > 0 )
9689 oid = oid . Substring ( 0 , index ) ;
97-
9890 return oid . Trim ( ) ;
99- }
100-
101- // Map OID to Certificate Type
102- string MapCertificateClass ( string oid )
103- {
104- switch ( oid )
105- {
106- case "2.16.356.100.2.1" :
107- return "Class 1 Certificate" ;
108-
109- case "2.16.356.100.2.2" :
110- return "Class 2 Certificate" ;
111-
112- case "2.16.356.100.2.3" :
113- return "Class 3 Certificate" ;
114-
115- case "2.16.840.1.114028.10.1.6" :
116- return "DocuSign High Assurance (Equivalent to Class 3)" ;
117-
118- default :
119- return "Unknown / Custom Certificate Policy" ;
120- }
12191}
0 commit comments