Class: Envault::Cryptor::Kms

Inherits:
Object
  • Object
show all
Defined in:
lib/envault/cryptor/kms.rb

Instance Method Summary collapse

Constructor Details

#initialize(profile) ⇒ Kms

Returns a new instance of Kms.



4
5
6
7
8
9
10
11
12
# File 'lib/envault/cryptor/kms.rb', line 4

def initialize(profile)
  require 'aws-sdk'
  options = {}
  options[:region] = profile[:region] if profile[:region]
  options[:access_key_id] = profile[:aws_access_key_id] if profile[:aws_access_key_id]
  options[:secret_access_key] = profile[:aws_secret_access_key] if profile[:aws_secret_access_key]
  @client = Aws::KMS::Client.new(options)
  @key_id = profile[:key_id]
end

Instance Method Details

#decrypt(value) ⇒ Object



19
20
21
22
# File 'lib/envault/cryptor/kms.rb', line 19

def decrypt(value)
  resp = @client.decrypt(ciphertext_blob: Base64.strict_decode64(value))
  resp.plaintext
end

#encrypt(value) ⇒ Object



14
15
16
17
# File 'lib/envault/cryptor/kms.rb', line 14

def encrypt(value)
  resp = @client.encrypt(key_id: @key_id, plaintext: value)
  Base64.strict_encode64(resp.ciphertext_blob)
end