Unprotect an OpenPGP file (alternative)
By ‘unprotecting’ we mean processing of protected file, whatever that may mean security-wise. While protected files may come in different forms and shapes (encrypted, signed, encrypted and signed), their processing by OpenPGPBlackbox is performed in a unified manner, which lets you process them in a more comfortable way.
You use TElPGPReader to process protected files. For the majority of cases, you will call its DecryptAndVerify() method (or DecryptAndVerifyFile(), if you wish to read input data from a file rather than from a stream). DecryptAndVerify() processes the protected file, informs you about the data in there and the security mechanisms applied to it, decrypts protected files and verifies any signatures included.
Note. The only exceptional case where you use a different processing method is when you need to verify a detached signature. In this case you call VerifyDetached() instead of DecryptAndVerify(), passing data and its signature(s) separately. Read more about specifics of processing of detached signatures.
Before calling DecryptAndVerify() you need to configure your TElPGPReader to provide it with access to decryption and verifying keys. You might also want to handle some events to keep yourself notified about the processing progress.
Load your public and secret keyring into a TElPGPKeyring object. You can use the same object for both public and secret keyrings, or use two different objects, depending on the way in which you manage your keys. Assign the keyring containing your decryption (secret) keys to DecryptingKeys property, and the keyring containing public keys of the originators to VerifyingKeys property:
reader.DecryptingKeys = secKeyring; reader.VerifyingKeys = pubKeyring;
Tune-up your TElPGPReader object by adjusting its properties. If you know the contents and security features of the protected files beforehand, you can adjust such properties as KeyPassphrase, Passphrase, OutputFile or OutputStream before processing the file instead of providing them on the fly via the object’s events.
Note. Passphrase property specifies the decryption password for conventional (password-based) encryption method. It has a totally different meaning to the passwords you use to encrypt your secret keys. Please use KeyPassphrase property to specify passwords for your secret keys.
Handle events exposed by TElPGPReader to keep yourself notified about the processing progress:
Finally, call DecryptAndVerify(), passing your data to it. Data processing may take some time, depending on the length of the input and the specifics of its protection. Once DecryptAndVerify() returns, your output media will contain the unprotected file. If any processing issues occur, DecryptAndVerify() will throw a relevant exception. Please analyse the exception message carefully to identify the reason for the problem.