Sha256: b42502ee580d784298e8f3710af4845649dd19337be549280a8704e9f76b1929

Contents?: true

Size: 709 Bytes

Versions: 6

Compression:

Stored size: 709 Bytes

Contents

module KmsEncrypted
  module Clients
    class Test < Base
      PREFIX = Base64.decode64("insecure+data+A")

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

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

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

        Base64.decode64(plaintext)
      end

      private

      # turn hash into json
      def generate_context(context)
        Base64.encode64(super)
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
kms_encrypted-1.2.1 lib/kms_encrypted/clients/test.rb
kms_encrypted-1.2.0 lib/kms_encrypted/clients/test.rb
kms_encrypted-1.1.1 lib/kms_encrypted/clients/test.rb
kms_encrypted-1.1.0 lib/kms_encrypted/clients/test.rb
kms_encrypted-1.0.1 lib/kms_encrypted/clients/test.rb
kms_encrypted-1.0.0 lib/kms_encrypted/clients/test.rb