class Lolitado::Box
Attributes
box[RW]
Public Class Methods
new(key)
click to toggle source
initialize box
@param key [String] ENV key value used for initialize box
# 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
Public Instance Methods
file_decrypt(file)
click to toggle source
decrypt file
@param file [String] the file need to be decrypted
# 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)
click to toggle source
encrypt file
@param file [String] the file need to be encrypted
# 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