Class: KmsEncrypted::Clients::Test

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

Constant Summary collapse

PREFIX =
Base64.decode64("insecure+data+A")

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



12
13
14
15
16
17
18
19
20
21
# File 'lib/kms_encrypted/clients/test.rb', line 12

def decrypt(ciphertext, context: nil)
  prefix, plaintext, stored_context = ciphertext.split(":")

  decryption_failed! if prefix != PREFIX

  context = generate_context(context) if context
  decryption_failed! if context != stored_context

  Base64.decode64(plaintext)
end

#encrypt(plaintext, context: nil) ⇒ Object



6
7
8
9
10
# File 'lib/kms_encrypted/clients/test.rb', line 6

def encrypt(plaintext, context: nil)
  parts = [PREFIX, Base64.strict_encode64(plaintext)]
  parts << generate_context(context) if context
  parts.join(":")
end