Sha256: f19278db7fe61f7cd314a14ecf2e004d175678441e1dcfa461e73e3de11628ee
Contents?: true
Size: 1.17 KB
Versions: 7
Compression:
Stored size: 1.17 KB
Contents
module KmsEncrypted module Clients class Google < Base attr_reader :last_key_version def encrypt(plaintext, context: nil) options = { plaintext: plaintext } options[:additional_authenticated_data] = generate_context(context) if context # ensure namespace gets loaded client = KmsEncrypted.google_client request = ::Google::Apis::CloudkmsV1::EncryptRequest.new(options) response = client.encrypt_crypto_key(key_id, request) @last_key_version = response.name response.ciphertext end def decrypt(ciphertext, context: nil) options = { ciphertext: ciphertext } options[:additional_authenticated_data] = generate_context(context) if context # ensure namespace gets loaded client = KmsEncrypted.google_client request = ::Google::Apis::CloudkmsV1::DecryptRequest.new(options) begin client.decrypt_crypto_key(key_id, request).plaintext rescue ::Google::Apis::ClientError => e decryption_failed! if e.message.include?("Decryption failed") raise e end end end end end
Version data entries
7 entries across 7 versions & 1 rubygems