Class: Mongo::ClientEncryption
- Inherits:
-
Object
- Object
- Mongo::ClientEncryption
- Defined in:
- 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.
33 34 35 36 37 38 39 |
# File 'lib/mongo/client_encryption.rb', line 33 def initialize(key_vault_client, ={}) @encrypter = Crypt::ExplicitEncrypter.new( key_vault_client, [:key_vault_namespace], [:kms_providers] ) 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.
63 64 65 66 67 68 |
# File 'lib/mongo/client_encryption.rb', line 63 def create_data_key(kms_provider, ={}) @encrypter.create_and_insert_data_key( kms_provider, ) end |
#decrypt(value) ⇒ Object
Decrypts a value that has already been encrypted.
99 100 101 |
# File 'lib/mongo/client_encryption.rb', line 99 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.
89 90 91 |
# File 'lib/mongo/client_encryption.rb', line 89 def encrypt(value, ={}) @encrypter.encrypt(value, ) end |