Class: Mongo::Crypt::ExplicitEncrypter Private
- Inherits:
-
Object
- Object
- Mongo::Crypt::ExplicitEncrypter
- Defined in:
- lib/mongo/crypt/explicit_encrypter.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
An ExplicitEncrypter is an object that performs explicit encryption operations and handles all associated options and instance variables.
Instance Method Summary collapse
-
#create_and_insert_data_key(kms_provider, options) ⇒ BSON::Binary
private
Generates a data key used for encryption/decryption and stores that key in the KMS collection.
-
#decrypt(value) ⇒ Object
private
Decrypts a value that has already been encrypted.
-
#encrypt(value, options) ⇒ BSON::Binary
private
Encrypts a value using the specified encryption key and algorithm.
-
#initialize(key_vault_client, key_vault_namespace, kms_providers) ⇒ ExplicitEncrypter
constructor
private
Create a new ExplicitEncrypter object.
Constructor Details
#initialize(key_vault_client, key_vault_namespace, kms_providers) ⇒ ExplicitEncrypter
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Create a new ExplicitEncrypter object.
32 33 34 35 36 37 38 39 |
# File 'lib/mongo/crypt/explicit_encrypter.rb', line 32 def initialize(key_vault_client, key_vault_namespace, kms_providers) @crypt_handle = Handle.new(kms_providers) @encryption_io = EncryptionIO.new( key_vault_client: key_vault_client, key_vault_namespace: key_vault_namespace ) end |
Instance Method Details
#create_and_insert_data_key(kms_provider, options) ⇒ BSON::Binary
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Generates a data key used for encryption/decryption and stores that key in the KMS collection. The generated key is encrypted with the KMS master key.
63 64 65 66 67 68 69 70 71 72 |
# File 'lib/mongo/crypt/explicit_encrypter.rb', line 63 def create_and_insert_data_key(kms_provider, ) data_key_document = Crypt::DataKeyContext.new( @crypt_handle, @encryption_io, kms_provider, ).run_state_machine @encryption_io.insert_data_key(data_key_document).inserted_id end |
#decrypt(value) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Decrypts a value that has already been encrypted
108 109 110 111 112 113 114 |
# File 'lib/mongo/crypt/explicit_encrypter.rb', line 108 def decrypt(value) result = Crypt::ExplicitDecryptionContext.new( @crypt_handle, @encryption_io, { 'v': value }, ).run_state_machine['v'] end |
#encrypt(value, options) ⇒ BSON::Binary
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The :key_id and :key_alt_name options are mutually exclusive. Only one is required to perform explicit encryption.
Encrypts a value using the specified encryption key and algorithm
93 94 95 96 97 98 99 100 |
# File 'lib/mongo/crypt/explicit_encrypter.rb', line 93 def encrypt(value, ) Crypt::ExplicitEncryptionContext.new( @crypt_handle, @encryption_io, { 'v': value }, ).run_state_machine['v'] end |