Method: HexaPDF::Document#encrypt
- Defined in:
- lib/hexapdf/document.rb
#encrypt(name: :Standard, **options) ⇒ Object
Encrypts the document.
Encryption is done by setting up a security handler for this purpose and populating the trailer’s Encrypt dictionary accordingly. The actual encryption, however, is only done when writing the document.
The security handler used for encrypting is selected via the name argument. All other arguments are passed on to the security handler.
If the document should not be encrypted, the name argument has to be set to nil. This removes the security handler and deletes the trailer’s Encrypt dictionary.
See: Encryption::SecurityHandler#set_up_encryption and Encryption::StandardSecurityHandler::EncryptionOptions for possible encryption options.
Examples:
document.encrypt(name: nil) # remove the existing encryption
document.encrypt(algorithm: :aes, key_length: 256, permissions: [:print, :extract_content]
650 651 652 653 654 655 656 657 |
# File 'lib/hexapdf/document.rb', line 650 def encrypt(name: :Standard, **) if name.nil? trailer.delete(:Encrypt) @security_handler = nil else @security_handler = Encryption::SecurityHandler.set_up_encryption(self, name, **) end end |