Class: KmsEncrypted::Clients::Aws

Inherits:
Base
  • Object
show all
Defined in:
lib/kms_encrypted/clients/aws.rb

Instance Attribute Summary

Attributes inherited from Base

#key_id

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from KmsEncrypted::Clients::Base

Instance Method Details

#decrypt(ciphertext, context: nil) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/kms_encrypted/clients/aws.rb', line 14

def decrypt(ciphertext, context: nil)
  options = {
    ciphertext_blob: ciphertext
  }
  options[:encryption_context] = generate_context(context) if context

  begin
    KmsEncrypted.aws_client.decrypt(options).plaintext
  rescue ::Aws::KMS::Errors::InvalidCiphertextException
    decryption_failed!
  end
end

#encrypt(plaintext, context: nil) ⇒ Object



4
5
6
7
8
9
10
11
12
# File 'lib/kms_encrypted/clients/aws.rb', line 4

def encrypt(plaintext, context: nil)
  options = {
    key_id: key_id,
    plaintext: plaintext
  }
  options[:encryption_context] = generate_context(context) if context

  KmsEncrypted.aws_client.encrypt(options).ciphertext_blob
end