unprotect Method
Unprotects the data.
Syntax
def unprotect() -> None: ...
Remarks
on_unprotect unprotects the specified data.
The class supports unprotecting data using either the classic DPAPI or CNG DPAPI implementation. The use of use_cng determines which implementation is used. The list of applicable properties differs depending on whether CNG DPAPI is being used.
When using classic DPAPI (use_cng is False), the following optional properties are applicable:
- data_description (populated after completion)
- password
When using CNG DPAPI (use_cng is True), the following properties are applicable:
- protection_descriptor (populated after completion)
- UseStreamMode
Input and Output Properties
The class will determine the source and destination of the input and output based on which properties are set.
The order in which the input properties are checked is as follows:
When a valid source is found the search stops. The order in which the output properties are checked is as follows:
- output_file
- output_message: The output data is written to this property if no other destination is specified.
Code Example (Classic DPAPI - use_cng is False)
//Protect
Dpapi dpapi = new Dpapi();
dpapi.InputMessage = "test";
dpapi.Protect();
byte[] protectedData = dpapi.OutputMessageB;
//Unprotect
dpapi = new Dpapi();
dpapi.InputMessageB = protectedData;
dpapi.Unprotect();
Console.WriteLine(dpapi.OutputMessage); //outputs "test"
Code Example (CNG DPAPI - use_cng is True)
//Protect
Dpapi dpapi = new Dpapi();
dpapi.UseCNG = true;
dpapi.ProtectionDescriptor = "LOCAL=user";
dpapi.InputMessage = "test";
dpapi.Protect();
byte[] protectedData = dpapi.OutputMessageB;
//Unprotect
dpapi = new Dpapi();
dpapi.UseCNG = true;
dpapi.InputMessageB = protectedData;
dpapi.Unprotect();
Console.WriteLine(dpapi.OutputMessage); //outputs "test"