![]() ![]() ![]() FileSize ( )įile_reader = FilterReader (trusted_cert_file ) Trusted_cert_file = MappedFile (in_public_key_file_path )įile_sz = trusted_cert_file. e_compatibility_and_archiving ) # Trust the public certificate we use for signing. Opts = VerificationOptions (VerificationOptions. e_verified : print ( "All signed signatures in document verified." ) return True else : print ( "unrecognized document verification status" ) assert False, "unrecognized document status" def VerifyAllAndPrint (in_docpath, in_public_key_file_path ) : e_unsupported : # If necessary, call GetUnsupportedFeatures on VerificationResult to check which # unsupported features were encountered (requires verification using 'detailed' APIs) print ( "At least one signature contains unsupported features." ) return False # unsigned sigs skipped parts of document may be unsigned (check GetByteRanges on signed sigs to find out) elif result is PDFDoc. e_untrusted : print ( "Could not verify trust for at least one signature." ) return False elif result is PDFDoc. e_failure : print ( "Hard failure in verification on at least one signature." ) return False elif result is PDFDoc. does not include trust issues, because those are flaky due to being network/config-related) elif result is PDFDoc. e_unsigned : print ( "Document has no signed signature fields." ) return False # e_failure = bad doc status, digest status, or permissions status # (i.e. VerifySignedDigitalSignatures (opts ) if result is PDFDoc. AddTrustedCertificate (in_public_key_file_path, VerificationOptions. e_compatibility_and_archiving ) # Add trust root to store of trusted certificates contained in VerificationOptions. append ( "././LicenseKey/PYTHON" ) from LicenseKey import * def VerifySimple (in_docpath, in_public_key_file_path ) :ĭoc = PDFDoc (in_docpath ) print ( "=" ) addsitedir ( "./././PDFNetC/Lib" ) import sys # Although the steps above describes extending the SignatureHandler class, this sample demonstrates the use of # StdSignatureHandler (a built-in SignatureHandler in PDFNet) to sign a PDF file. This can be used to # add additional information to the signature dictionary (e.g. For example, UseSignatureHandler() returns an instance # of SDF dictionary which represents the signature dictionary (or the /V entry of the form field). # Additional processing can be done before document is signed. # IMPORTANT: If there are already signed/certified digital signature(s) in the document, you must save incrementally # so as to not invalidate the other signature(s). This will also create the digital signature dictionary and write a cryptographic signature to it. # NOTE: It is only possible to sign/certify one signature per call to the Save function. # iii)Ĝall SignOnNextSaveWithCustomHandler/CertifyOnNextSaveWithCustomHandler with the SignatureHandlerId. # ii) Create an instance of the implemented SignatureHandler and register it with PDFDoc with # pdfdoc.AddSignatureHandler(). The SignatureHandler will be used to add or # validate/check a digital signature. This overload is to be used # in the following fashion: # i) Extend and implement a new SignatureHandler. Taking a unique identifier of a signature handler registered with the PDFDoc. Taking a buffer containing a PKCS #12 private keyfile and its password # c. Taking a PKCS #12 keyfile path and its password # b. There are three overloads for each one (six total): # a. ![]() Call either CertifyOnNextSave or SignOnNextSave. # If you want it to be visible, provide a Rect argument with a non-zero width or height, and don't set the # NoView and Hidden flags. #Ē.Ĝreate a signature widget annotation, and pass the DigitalSignatureField that you just created or found. # -OR- # (b) If you didn't just create the digital signature field that you want to sign/certify, find the existing one within the # document by using PDFDoc.DigitalSignatureFieldIterator or by using PDFDoc.GetField to get it by its fully qualified name. #đ.ĞITHER: # (a) Call doc.CreateDigitalSignatureField, optionally providing a name. Start with a PDF with or without form fields in it that one would like to lock (or, one can add a field, see (1)). # The following steps reflect typical intended usage of the digital signatures API: #Đ. #- #- # This sample demonstrates the basic usage of the high-level digital signatures API in PDFNet. # Consult LICENSE.txt regarding license information. #!/usr/bin/python #- # Copyright (c) 2001-2023 by Apryse Software Inc. ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |