Module: Linecook::Crypto

Included in:
Image
Defined in:
lib/linecook-gem/image/crypt.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.keygenObject


6
7
8
# File 'lib/linecook-gem/image/crypt.rb', line 6

def self.keygen
   RbNaCl::Random.random_bytes(RbNaCl::SecretBox.key_bytes).unpack('H*').first
end

Instance Method Details

#decrypt(source, dest: nil) ⇒ Object


16
17
18
19
20
# File 'lib/linecook-gem/image/crypt.rb', line 16

def decrypt(source, dest: nil)
  dest ||= "/tmp/#{File.basename(source)}-decrypted"
  File.write(dest, box.decrypt(IO.binread(source)))
  dest
end

#encrypt(source, dest: nil) ⇒ Object


10
11
12
13
14
# File 'lib/linecook-gem/image/crypt.rb', line 10

def encrypt(source, dest: nil)
  dest ||= "/tmp/#{File.basename(source)}"
  File.write(dest, box.encrypt(IO.binread(source)))
  dest
end