Class: Mongo::ClientEncryption
- 继承:
-
对象
- 对象
- Mongo::ClientEncryption
- 定义于:
- lib/ Mongo/client_encryption.rb
Overview
ClientEncryption 封装了对密钥保管库集合的显式操作,这些操作无法直接在 MongoClient 上完成。 它提供了一个 API,用于显式加密和解密值以及创建数据密钥。
实例方法摘要折叠
-
#add_key_alt_name(id, key_alt_name) ⇒ BSON::Document | nil
在具有给定 ID 的密钥保管库集合中为密钥添加 key_alt_name。
-
# create_data_key (kms_provider, options = {}) ⇒ BSON::Binary
生成用于加密/解密的数据密钥,并将该密钥存储在 KMS 集合中。
-
# create_encrypted_collection (database, coll_name, coll_opts, kms_provider, master_key) ⇒ Array<Operation::Result, Hash>
使用加密字段创建集合。
-
#解密(值) ⇒ 对象
对已加密的值进行解密。
-
# delete_key ( ID ) ="Operation::Result"
从密钥保管库集合中删除具有给定 ID 的密钥。
-
# encrypt (value, options = {}) ⇒ BSON::Binary
使用指定的加密密钥和算法加密值。
-
# encrypt_expression (表达式, options = {}) ⇒ BSON::Binary
加密匹配表达式或聚合表达式以查询范围索引。
-
# get_key ( ID ) ⇒ BSON::Document | nil
查找具有给定 ID 的单个键。
-
#get_key_by_alt_name(key_alt_name) ⇒ BSON::Document | nil
返回密钥保管库集合中具有给定 key_alt_name 的密钥。
-
# get_keys ⇒ Collection::View (也:#keys)
返回密钥保管库集合中的所有密钥。
-
#initialize(key_vault_client, options = {}) ⇒ ClientEncryption
构造函数
使用提供的选项创建新的 ClientEncryption 对象。
-
# remove_key_alt_name ( ID , key_alt_name) ⇒ BSON::Document | nil
从密钥保管库集合中具有给定 ID 的密钥中删除 key_alt_name。
-
# rewrap_many_data_key (filter, opts = {}) ⇒ Crypt::RewrapManyDataKeyResult
解密多个数据密钥,并使用新的 master_key(重新)加密它们;如果未给出新密钥,则使用当前的 master_key。
构造函数详情
#initialize(key_vault_client, options = {}) ⇒ ClientEncryption
使用提供的选项创建新的 ClientEncryption 对象。
49 50 51 52 53 54 55 56 |
# File 'lib/ Mongo/client_encryption.rb', line 49 def 初始化(key_vault_client, = {}) @encrypter = Crypt::ExplicitEncrypter.new( key_vault_client, [:key_vault_namespace], Crypt::KMS::凭证.new([:kms_providers]), Crypt::KMS::验证.([:kms_tls_options]) ) end |
实例方法详细信息
# add_key_alt_name ( ID , key_alt_name) ⇒ BSON::Document | nil
在具有给定 ID 的密钥保管库集合中为密钥添加 key_alt_name。
183 184 185 |
# File 'lib/ Mongo/client_encryption.rb', line 183 def add_key_alt_name(id, key_alt_name) @encrypter.add_key_alt_name(id, key_alt_name) end |
# create_data_key (kms_provider, options = {}) ⇒ BSON::Binary
生成用于加密/解密的数据密钥,并将该密钥存储在 KMS 集合中。 生成的密钥使用 KMS 主密钥进行加密。
84 85 86 87 88 89 90 |
# File 'lib/ Mongo/client_encryption.rb', line 84 def create_data_key(kms_provider, ={}) key_document = Crypt::KMS::MasterKeyDocument.new(kms_provider, ) key_alt_names = [:key_alt_names] key_material = [:key_material] @encrypter.create_and_insert_data_key(key_document, key_alt_names, key_material) end |
# create_encrypted_collection (数据库, coll_name, coll_opts, kms_provider, master_key) ⇒ Array< Operation::Result , Hash>
此方法不会更新客户端的 :auto_encryption_options 中的 :encrypted_fields_map。 因此,为了使用通过此方法创建的集合进行自动加密,用户必须在调用此函数并返回 :encrypted_fields 后创建一个新客户端。
使用加密字段创建集合。
如果 :encryption_fields 包含具有 null 值的 keyId,则会自动生成数据密钥并将其分配给 keyId 值。
270 271 272 273 274 275 276 277 278 279 280 281 |
# File 'lib/ Mongo/client_encryption.rb', line 270 def create_encrypted_collection(database, coll_name, coll_opts, kms_provider, master_key) 提高 ArgumentError, ' coll_opts must contains :encrypted_fields ' 除非 coll_opts[:encrypted_fields] encryption_fields = create_data_keys(coll_opts[:encrypted_fields], kms_provider, master_key) 开始 new_coll_opts = coll_opts.dup.合并(merge)(encryption_fields: encryption_fields) [database[coll_name].创建(new_coll_opts), encryption_fields] 救援 mongo::错误 => e 提高 错误::CryptError, " 创建包含加密字段的集合时出错 \ # { encryption_fields } : #{ e . class } : #{ e . } " end end |
#解密(值) ⇒对象
对已加密的值进行解密。
172 173 174 |
# File 'lib/ Mongo/client_encryption.rb', line 172 def 解密(值) @encrypter.解密(值) end |
# delete_key ( ID ) = "Operation::Result"
从密钥保管库集合中删除具有给定 ID 的密钥。
193 194 195 |
# File 'lib/ Mongo/client_encryption.rb', line 193 def delete_key(id) @encrypter.delete_key(id) end |
# encrypt (value, options = {}) ⇒ BSON::Binary
:key_id 和 :key_alt_name 选项是互斥的。 只需一次即可执行显式加密。
使用指定的加密密钥和算法加密值。
如果加密算法设立为“Indexed”。 应设立查询类型
only if encryption algorithm is set to "Indexed". The only allowed
value is "equality".
122 123 124 |
# File 'lib/ Mongo/client_encryption.rb', line 122 def 加密(值, ={}) @encrypter.加密(值, ) end |
# encrypt_expression (expression, options = {}) ⇒ BSON::Binary
:key_id 和 :key_alt_name 选项是互斥的。 只需一次即可执行显式加密。
加密匹配表达式或聚合表达式以查询范围索引。
仅当 queryType 为“范围”且算法为“ Range ”时才支持。 @note:Range算法仅处于实验阶段。 这不是为了
for public use. It is subject to breaking changes.
# @param [ Hash ] options
162 163 164 |
# File 'lib/ Mongo/client_encryption.rb', line 162 def encrypt_expression(表达式(expression), = {}) @encrypter.encrypt_expression(表达式(expression), ) end |
#get_key(id) ⇒ BSON::Document | nil
查找具有给定 ID 的单个键。
203 204 205 |
# File 'lib/ Mongo/client_encryption.rb', line 203 def get_key(id) @encrypter.get_key(id) end |
# get_key_by_alt_name (key_alt_name) ⇒ BSON::Document | nil
返回密钥保管库集合中具有给定 key_alt_name 的密钥。
213 214 215 |
# File 'lib/ Mongo/client_encryption.rb', line 213 def get_key_by_alt_name(key_alt_name) @encrypter.get_key_by_alt_name(key_alt_name) end |
# get_keys ⇒ Collection::View也称为:键
返回密钥保管库集合中的所有密钥。
220 221 222 |
# File 'lib/ Mongo/client_encryption.rb', line 220 def get_keys @encrypter.get_keys end |
# remove_key_alt_name ( ID , key_alt_name) ⇒ BSON::Document | nil
从密钥保管库集合中具有给定 ID 的密钥中删除 key_alt_name。
232 233 234 |
# File 'lib/ Mongo/client_encryption.rb', line 232 def remove_key_alt_name(id, key_alt_name) @encrypter.remove_key_alt_name(id, key_alt_name) end |
# rewrap_many_data_key (过滤, opts = {}) ⇒ Crypt::RewrapManyDataKeyResult
解密多个数据密钥并使用新的 master_key(重新)加密它们,
or with their current master_key if a new one is not given.
247 248 249 |
# File 'lib/ Mongo/client_encryption.rb', line 247 def rewrap_many_data_key(筛选器, opts = {}) @encrypter.rewrap_many_data_key(筛选器, opts) end |