class Infovault

Public Instance Methods

encrypt(key,value,pass_phrase,salt=OpenSSL::Random.random_bytes(8),file="") click to toggle source

Encrypt encrypt(“key”,“value”,“password”,OpenSSL::Random.random_bytes(8))

# File lib/info_vault/cli.rb, line 9
def encrypt(key,value,pass_phrase,salt=OpenSSL::Random.random_bytes(8),file="")
  file = File.open(File.expand_path(File.join('config','protected_info.yaml')),'w') if file.empty?
  encrypter = OpenSSL::Cipher.new 'AES-128-CBC'
  encrypter.encrypt
  encrypter.pkcs5_keyivgen pass_phrase, salt

  encrypted = encrypter.update value
  encrypted << encrypter.final
  password = {key.to_sym => {:salt => salt,:encrypted => encrypted}}
  File.open(file, 'w') {|f| f.write(password.to_yaml) }
end