Module: LucaSupport::Enc

Defined in:
lib/luca_support/enc.rb

Overview

Encrypt/Decrypt directory with openssl command

Class Method Summary collapse

Class Method Details

.decrypt(dir, iter: 10000) ⇒ Object

TODO: check space in dir string



28
29
30
31
32
33
34
35
# File 'lib/luca_support/enc.rb', line 28

def decrypt(dir, iter: 10000)
  passopt = ENV['LUCA_ENC_PASSWORD'] ? "-pass pass:#{ENV['LUCA_ENC_PASSWORD']}" : ''
  Dir.chdir(Pathname(CONST.pjdir) / 'data') do
    abort "Archive #{dir}.tar.gz not found. exit..." unless File.exist?("#{dir}.tar.gz")

    system "openssl enc -d -aes256 -iter #{iter} -in #{dir}.tar.gz #{passopt} | tar xz"
  end
end

.encrypt(dir, iter: 10000, cleanup: false) ⇒ Object

TODO: check if openssl/tar exists TODO: handle multiple directories TODO: check space in dir string TODO: check if origin exists



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/luca_support/enc.rb', line 15

def encrypt(dir, iter: 10000, cleanup: false)
  passopt = ENV['LUCA_ENC_PASSWORD'] ? "-pass pass:#{ENV['LUCA_ENC_PASSWORD']}" : ''
  Dir.chdir(Pathname(CONST.pjdir) / 'data') do
    abort "Directory #{dir} not found. exit..." unless Dir.exist?(dir)

    system "tar czf - #{dir} | openssl enc -e -aes256 -iter #{iter} -out #{dir}.tar.gz #{passopt}"
    return if ! cleanup

    FileUtils.rm_rf dir
  end
end