Module: Vault::Rails

Defined in:
lib/vault/rails.rb,
lib/vault/rails/testing.rb,
lib/vault/rails/version.rb

Defined Under Namespace

Modules: Testing

Constant Summary collapse

VERSION =
"0.1.2"

Class Method Summary collapse

Class Method Details

.decrypt(path, key, ciphertext) ⇒ Object

See Also:



59
60
61
62
63
# File 'lib/vault/rails.rb', line 59

def self.decrypt(path, key, ciphertext)
  route  = File.join(path, "decrypt", key)
  secret = Vault.logical.write(route, ciphertext: ciphertext)
  return Base64.strict_decode64(secret.data[:plaintext])
end

.decrypt_originalString

Decrypt the given ciphertext data using the provided mount and key.

Parameters:

  • path (String)

    the mount point

  • key (String)

    the key to decrypt at

  • ciphertext (String)

    the ciphertext to decrypt

Returns:

  • (String)

    the decrypted plaintext text



36
37
38
39
40
# File 'lib/vault/rails/testing.rb', line 36

def self.decrypt(path, key, ciphertext)
  route  = File.join(path, "decrypt", key)
  secret = Vault.logical.write(route, ciphertext: ciphertext)
  return Base64.strict_decode64(secret.data[:plaintext])
end

.encrypt(path, key, plaintext) ⇒ Object

See Also:



40
41
42
43
44
45
46
# File 'lib/vault/rails.rb', line 40

def self.encrypt(path, key, plaintext)
  route  = File.join(path, "encrypt", key)
  secret = Vault.logical.write(route,
    plaintext: Base64.strict_encode64(plaintext),
  )
  return secret.data[:ciphertext]
end

.encrypt_originalString

Encrypt the given plaintext data using the provided mount and key.

Parameters:

  • path (String)

    the mount point

  • key (String)

    the key to encrypt at

  • plaintext (String)

    the plaintext to encrypt

Returns:

  • (String)

    the encrypted cipher text



35
36
37
38
39
40
41
# File 'lib/vault/rails/testing.rb', line 35

def self.encrypt(path, key, plaintext)
  route  = File.join(path, "encrypt", key)
  secret = Vault.logical.write(route,
    plaintext: Base64.strict_encode64(plaintext),
  )
  return secret.data[:ciphertext]
end