Class: Lolitado::Box
- Inherits:
-
Object
- Object
- Lolitado::Box
- Defined in:
- lib/lolitado/box.rb
Instance Attribute Summary collapse
-
#box ⇒ Object
Returns the value of attribute box.
Instance Method Summary collapse
-
#file_decrypt(file) ⇒ Object
decrypt file.
-
#file_encrypt(file) ⇒ Object
encrypt file.
-
#initialize(key) ⇒ Box
constructor
initialize box.
Constructor Details
#initialize(key) ⇒ Box
initialize box
14 15 16 17 18 |
# File 'lib/lolitado/box.rb', line 14 def initialize key fail "There's no environment variable #{key}..." if ENV[key].nil? key = Base64.decode64(ENV[key]) @box = RbNaCl::SimpleBox.from_secret_key(key) end |
Instance Attribute Details
#box ⇒ Object
Returns the value of attribute box.
7 8 9 |
# File 'lib/lolitado/box.rb', line 7 def box @box end |
Instance Method Details
#file_decrypt(file) ⇒ Object
decrypt file
37 38 39 40 41 42 |
# File 'lib/lolitado/box.rb', line 37 def file_decrypt file ciphertext = File.read(file) plaintext = box.decrypt(Base64.decode64(ciphertext)) plain_file = file[0..-5] File.write(plain_file, plaintext) end |
#file_encrypt(file) ⇒ Object
encrypt file
25 26 27 28 29 30 |
# File 'lib/lolitado/box.rb', line 25 def file_encrypt file plaintext = File.read(file) ciphertext = box.encrypt(plaintext) enc_file = file + '.enc' File.write(enc_file, Base64.encode64(ciphertext)) end |