Loading Encrypted Files Using the Document Library

Some documents formats (such as PDF, DOC, DOCX, XLS, XLSX, etc), support optional encryption and require being decrypted with a password before they can be used.

When using the DocumentFactory to load such documents, a LEADDocument object is created and returned as usual. However, it will be encrypted and unusable until the correct password is applied to decrypt it. Unusable means that only the information properties of the document are available (such as its DocumentId, DocumentType and MimeType). The Pages collection will be empty and cannot interact with the document by getting any more information from it.

There are two ways to pass the password phrase needed to decrypt a document:

  1. Set the password in the LoadDocumentOptions.Password property. This is the easiest way but requires the correct password to be available before the document is loaded. If the document is in a remote location and is loaded using DocumentFactory.LoadFromUri, then it will be downloaded to the cache or a temporary file before having the password applied.

    If the password is wrong, an exception will be thrown and the document will be deleted.

    Retrying with another password requires the application to call DocumentFactory.LoadFromUri again, and repeat the entire process (a non-optimal solution).

  2. Call the DocumentFactory.LoadFromUri with LoadDocumentOptions.Password set to null. A LEADDocument will be returned with the following property values:

    If the Document is encrypted, then the value of LEADDocument.IsEncrypted is set to true by the factory. And the value of LEADDocument.IsDecrypted, is intialized to false.

    The application can check for this condition and then prompt the user for the password phrase. It can then call LEADDocument.Decrypt with the password as many times as needed while checking the LEADDocument.IsDecrypted property. When this property becomes true, it means the correct password was applied and the document is unlocked and ready to use.

    For an example, refer to LEADDocument.IsEncrypted

See Also

Document Library Features

Loading Using LEADTOOLS Document Library

Creating Documents with LEADTOOLS Document Library

Document Toolkit and Caching

Uploading Using the Document Library

Document Library Coordinate System

Parsing Text with the Document Library

Barcode processing with the Document Library

Document Toolkit History Tracking

Document Page Transformation

Using LEADTOOLS Document Viewer

Using LEADTOOLS Document Converters

Document View and Convert Redaction

Help Version 21.0.2021.11.1
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2021 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS Imaging, Medical, and Document
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2021 LEAD Technologies, Inc. All Rights Reserved.