Class: Mongo::ClientEncryption
- Inherits:
-
Object
- Object
- Mongo::ClientEncryption
- Defined in:
- build/ruby-driver-master/lib/mongo/client_encryption.rb
Overview
ClientEncryption encapsulates explicit operations on a key vault collection that cannot be done directly on a MongoClient. It provides an API for explicitly encrypting and decrypting values, and creating data keys.
Instance Method Summary collapse
-
#create_data_key(kms_provider, options = {}) ⇒ BSON::Binary
Generates a data key used for encryption/decryption and stores that key in the KMS collection.
-
#decrypt(value) ⇒ Object
Decrypts a value that has already been encrypted.
-
#encrypt(value, options = {}) ⇒ BSON::Binary
Encrypts a value using the specified encryption key and algorithm.
-
#initialize(key_vault_client, options = {}) ⇒ ClientEncryption
constructor
Create a new ClientEncryption object with the provided options.
Constructor Details
#initialize(key_vault_client, options = {}) ⇒ ClientEncryption
Create a new ClientEncryption object with the provided options.
46 47 48 49 50 51 52 53 |
# File 'build/ruby-driver-master/lib/mongo/client_encryption.rb', line 46 def initialize(key_vault_client, ={}) @encrypter = Crypt::ExplicitEncrypter.new( key_vault_client, [:key_vault_namespace], Crypt::KMS::Credentials.new([:kms_providers]), Crypt::KMS::Validations.([:kms_tls_options]) ) end |
Instance Method Details
#create_data_key(kms_provider, options = {}) ⇒ BSON::Binary
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.
77 78 79 80 81 |
# File 'build/ruby-driver-master/lib/mongo/client_encryption.rb', line 77 def create_data_key(kms_provider, ={}) key_document = Crypt::KMS::MasterKeyDocument.new(kms_provider, ) key_alt_names = [:key_alt_names] @encrypter.create_and_insert_data_key(key_document, key_alt_names) end |
#decrypt(value) ⇒ Object
Decrypts a value that has already been encrypted.
112 113 114 |
# File 'build/ruby-driver-master/lib/mongo/client_encryption.rb', line 112 def decrypt(value) @encrypter.decrypt(value) end |
#encrypt(value, options = {}) ⇒ BSON::Binary
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.
102 103 104 |
# File 'build/ruby-driver-master/lib/mongo/client_encryption.rb', line 102 def encrypt(value, ={}) @encrypter.encrypt(value, ) end |