Class: YamlVault::Main::ValueCryptor::Simple

Inherits:
Object
  • Object
show all
Defined in:
lib/yaml_vault.rb

Instance Method Summary collapse

Constructor Details

#initialize(passphrase, sign_passphrase, salt, cipher, digest, key_size = 32, signature_key_size = 64) ⇒ Simple

Returns a new instance of Simple.



98
99
100
101
102
103
104
105
106
107
# File 'lib/yaml_vault.rb', line 98

def initialize(passphrase, sign_passphrase, salt, cipher, digest, key_size = 32, signature_key_size = 64)
  key = ActiveSupport::KeyGenerator.new(passphrase).generate_key(salt, key_size)
  signature_key = ActiveSupport::KeyGenerator.new(sign_passphrase).generate_key(salt, signature_key_size) if sign_passphrase

  if signature_key
    @cryptor = ActiveSupport::MessageEncryptor.new(key, signature_key, cipher: cipher, digest: digest)
  else
    @cryptor = ActiveSupport::MessageEncryptor.new(key, cipher: cipher, digest: digest)
  end
end

Instance Method Details

#decrypt(value) ⇒ Object



113
114
115
# File 'lib/yaml_vault.rb', line 113

def decrypt(value)
  @cryptor.decrypt_and_verify(value)
end

#encrypt(value) ⇒ Object



109
110
111
# File 'lib/yaml_vault.rb', line 109

def encrypt(value)
  @cryptor.encrypt_and_sign(value)
end