Class: PGP::Encryptor
- Inherits:
-
Object
- Object
- PGP::Encryptor
- Defined in:
- lib/pgp/encryptor.rb
Instance Attribute Summary collapse
-
#recipients ⇒ Object
Returns the value of attribute recipients.
Instance Method Summary collapse
- #add_keys(key_string) ⇒ Object
- #add_keys_from_file(filename) ⇒ Object
- #encrypt(cleartext, filename = nil, mtime = nil) ⇒ Object
- #encrypt_file(file_path) ⇒ Object
-
#initialize(key_string = nil) ⇒ Encryptor
constructor
A new instance of Encryptor.
Constructor Details
#initialize(key_string = nil) ⇒ Encryptor
Returns a new instance of Encryptor.
5 6 7 8 |
# File 'lib/pgp/encryptor.rb', line 5 def initialize(key_string=nil) self.recipients = [] add_keys(key_string) if key_string end |
Instance Attribute Details
#recipients ⇒ Object
Returns the value of attribute recipients.
3 4 5 |
# File 'lib/pgp/encryptor.rb', line 3 def recipients @recipients end |
Instance Method Details
#add_keys(key_string) ⇒ Object
10 11 12 |
# File 'lib/pgp/encryptor.rb', line 10 def add_keys(key_string) self.recipients += GPG::Engine.new.import_key(key_string) end |
#add_keys_from_file(filename) ⇒ Object
14 15 16 |
# File 'lib/pgp/encryptor.rb', line 14 def add_keys_from_file(filename) add_keys(File.read(filename)) end |
#encrypt(cleartext, filename = nil, mtime = nil) ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/pgp/encryptor.rb', line 18 def encrypt(cleartext, filename=nil, mtime=nil) result = GPG::Engine.new.encrypt(cleartext, recipients) unless filename.nil? File.write(filename, result[1]) end result[1] end |
#encrypt_file(file_path) ⇒ Object
28 29 30 |
# File 'lib/pgp/encryptor.rb', line 28 def encrypt_file(file_path) encrypt(File.read(file_path)) end |