Event used to provide the password for loading encrypted files.
public event EventHandler<CodecsDecryptPasswordEventArgs> DecryptPassword public:event EventHandler<CodecsDecryptPasswordEventArgs^>^ DecryptPassword
def DecryptPassword(sender,e): # sender: RasterCodecs e: CodecsDecryptPasswordEventArgs
| Parameter | Type | Description |
|---|---|---|
| sender | object | The source of the event |
| e | CodecsDecryptPasswordEventArgs | The event data |
You need to provide a password for loading or retrieving information about encrypted files.
If you register a DecryptPassword event handler, RasterCodecs automatically fires the DecryptPassword event when attempting to load or to get information about an encrypted file. The operation can only succeed when setting the CodecsDecryptPasswordEventArgs.Password property in the event handler to the correct password.
Another way to provide the password is to set the RasterCodecs.CodecsLoadOptions.Decrypt.Password property beforehand. If the RasterCodecs.CodecsLoadOptions.Decrypt.Password property is set to the correct password, the DecryptPassword event will not fire. In other words, the DecryptPassword event is fired only if RasterCodecs.CodecsLoadOptions.Decrypt.Password is incorrect.
For PDF files, the DecryptPassword event is fired if both RasterCodecs.CodecsLoadOptions.Decrypt.Password and RasterCodecs.Load.Pdf.Password are incorrect.
A typical event handler will bring up a message box containing an edit box and a label with a message: "File XXX is encrypted. Please provide the password for opening this file". The event handler then return the password provided to LEADTOOLS using the CodecsDecryptPasswordEventArgs parameter. The name of the file that triggered the event is in the CodecsDecryptPasswordEventArgs.FileName property.
If the password supplied in DecryptPassword is incorrect, the event handler will be called again until:
1) The event handler returns the correct password.
or
2) The event handler aborts the operation gracefully by setting the CodecsDecryptPasswordEventArgs.Cancel property to true.
or
3) The event handler returns the same incorrect password twice in a row for the same file (the operation is aborted in this case to avoid a possible infinite loop).
If the current operation is cancelled by setting CodecsDecryptPasswordEventArgs.Cancel to true, RasterCodecs Class gracefully cancels the operation without firing an exception and GetInformation, Load/LoadSvg return as follows:
In other words, the application should not rely on the exception mechanism and check the returned object as described above to detect whether the user aborted the operation.
You should be very careful to avoid going into an infinite loop. For example, if you always return the same password from this event and the password is incorrect, the app will lock up because the event will keep getting fired.
using Leadtools;using Leadtools.Codecs;using Leadtools.ImageProcessing;using Leadtools.ImageProcessing.Color;using Leadtools.Svg;private static void DecryptPasswordExample(){/* This example loads an encrypted file using the Decrypt password event */using (RasterCodecs codecs = new RasterCodecs()){string srcFile = @"Encrypted.docx";// Create a DecryptPassword handlerEventHandler<CodecsDecryptPasswordEventArgs> decryptPasswordHandler = (sender, e) =>{/* You can also bring up a message box informing the user that the 'e.FileName' file is encrypted and needs a password */e.Password = "MyPassword";/* Or you can set 'e.Cancel = true' to cancel the load */};// Install the DecryptPassword event handlercodecs.DecryptPassword += decryptPasswordHandler;codecs.Options.Load.AllPages = true;using (RasterImage image = codecs.Load(srcFile)){/* check that the image is not null to make sure the operation was not cancelled */if (image != null)codecs.Save(image, srcFile + ".tif", RasterImageFormat.TifLzw, 0);}}}
import java.io.*;import java.net.*;import java.nio.file.Paths;import java.util.*;import java.time.Instant;import java.time.Duration;import org.junit.*;import org.junit.runner.JUnitCore;import org.junit.runner.Result;import org.junit.runner.notification.Failure;import static org.junit.Assert.*;import leadtools.*;import leadtools.codecs.*;import leadtools.codecs.RasterCodecs.FeedCallbackThunk;import leadtools.drawing.internal.*;import leadtools.imageprocessing.*;import leadtools.imageprocessing.color.ChangeIntensityCommand;import leadtools.svg.*;public void decryptPasswordExample() {// This example loads an encrypted file using the Decrypt password event //final String LEAD_VARS_IMAGES_DIR = "C:\\LEADTOOLS23\\Resources\\Images";String srcFile = combine(LEAD_VARS_IMAGES_DIR, "Encrypted.pdf");RasterCodecs codecs = new RasterCodecs();// Install the DecryptPassword event handlercodecs.addDecryptPasswordListener(decryptPasswordHandler);codecs.getOptions().getLoad().setAllPages(true);RasterImage image = codecs.load(srcFile);// check that the image is not null to make sure the operation was not cancelled// //if (image != null)codecs.save(image, srcFile + ".tif", RasterImageFormat.TIFLZW, 0);}// Create a DecryptPassword handlerCodecsDecryptPasswordListener decryptPasswordHandler = new CodecsDecryptPasswordListener() {@Overridepublic void onDecryptPassword(CodecsDecryptPasswordEvent e) {// You can also bring up a message box informing the user that the 'e.FileName'// file is encrypted and needs a password //e.setPassword("MyPassword");// Or you can set 'e.Cancel = true' to cancel the load //}};
CodecsDecryptPasswordEventArgs class
RasterCodecs.CodecsLoadOptions.Decrypt.Password property
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document
