Explicit Encryption显式加密
On this page本页内容
Overview概述
Learn how to use the explicit encryption mechanism of Queryable Encryption. Explicit encryption lets you specify the key material used to encrypt fields. 了解如何使用Queryable encryption的显式加密机制。显式加密允许您指定用于加密字段的键材料。It provides fine-grained control over security, at the cost of increased complexity when configuring collections and writing code for MongoDB Drivers.它提供了对安全性的细粒度控制,但在为MongoDB驱动程序配置集合和编写代码时会增加复杂性。
Explicit encryption is a mechanism in which you specify how to encrypt and decrypt fields in your document for each operation you perform on your database.显式加密是一种机制,在该机制中,您可以为对数据库执行的每个操作指定如何加密和解密文档中的字段。
Explicit encryption is available in the following MongoDB products:显式加密在以下MongoDB产品中可用:
- MongoDB Community Server
- MongoDB Enterprise Advanced
- MongoDB Atlas
Use Explicit Encryption使用显式加密
Create a ClientEncryption Instance创建ClientEncryption实例
ClientEncryption
is an abstraction used across drivers and mongosh
that encapsulates the Key Vault collection and KMS operations involved in explicit encryption.ClientEncryption
是一种跨驱动程序和mongosh
使用的抽象,它封装了显式加密中涉及的键库集合和KMS操作。
To create a 要创建ClientEncryption
instance, specify:ClientEncryption
实例,请指定:
AkmsProviders
object configured with access to the KMS hosting your Customer Master KeykmsProviders
对象配置为可以访问托管客户主键的KMSThe namespace of your Key Vault collection键库集合的命名空间If you use MongoDB Community Server, set the如果使用MongoDB Community Server,请将bypassQueryAnalysis
option toTrue
bypassQueryAnalysis
选项设置为True
A可以访问键库集合的MongoClient
instance with access to your Key Vault collectionMongoClient
实例
For more 有关更多ClientEncryption
options, see MongoClient Options for Queryable Encryption.ClientEncryption
选项,请参阅MongoClient可查询加密选项。
Encrypt Fields in Read and Write Operations读取和写入操作中的加密字段
You must update read and write operations throughout your application such that your application encrypts fields before performing read and write operations.您必须在整个应用程序中更新读写操作,以便应用程序在执行读写操作之前对字段进行加密。
To encrypt fields, use the 要加密字段,请使用encrypt
method of your ClientEncryption
instance. Specify the following:ClientEncryption
实例的encrypt
方法。指定以下内容:
The value to be encrypted要加密的值The algorithm used, either使用的算法,Indexed
orUnindexed
Indexed
(已索引)或Unindexed
(未索引)The ID of the Data Encryption Key数据加密键的IDThe contention factor (if you are using the争用因子(如果您使用的是Indexed
algorithm)Indexed
算法)If performing a read operation, set the query type defined for your field (if you are using the如果执行读取操作,请设置为字段定义的查询类型(如果使用的是Indexed
algorithm)Indexed
算法)
Query Types查询类型
The query type only applies to read operations.查询类型仅适用于读取操作。
To learn more about query types, see Query Types.要了解有关查询类型的详细信息,请参阅查询类型。
Algorithm Choice算法选择
Use the 如果在字段上指定Indexed
algorithm if you specify a queryType
on the field.queryType
,请使用Indexed
算法。
Indexed
supports equality queries. Indexed
支持相等查询。Indexed
fields require an index on the server. 字段需要服务器上的索引。The index is created by specifying the 通过在encryptedFields
option in db.createCollection()
.db.createCollection()
中指定encryptedFields
选项来创建索引。
Automatic Decryption自动解密
To decrypt fields automatically, configure your 要自动解密字段,请按如下方式配置MongoClient
instance as follows:MongoClient
实例:
Specify a指定kmsProviders
objectkmsProviders
对象Specify your Key Vault collection指定键保管库集合If you use MongoDB Community Server, set the如果使用MongoDB Community Server,请将bypassQueryAnalysis
option toTrue
bypassQueryAnalysis
选项设置为True
Automatic Decryption in MongoDB Community ServerMongoDB社区服务器中的自动解密
Automatic decryption is available in MongoDB Community Server. MongoDB Community Server提供自动解密功能。Automatic encryption requires MongoDB Enterprise or MongoDB Atlas.自动加密需要MongoDB Enterprise或MongoDB Atlas。
Server-Side Field Level Encryption Enforcement服务器端字段级加密强制
Specify Fields for Encryption指定加密字段 to enforce encryption of specific fields in a collection.以强制对集合中的特定字段进行加密。
Indexed
fields require an index on the server. 字段需要服务器上的索引。The index is created by specifying the 通过在encryptedFields
option in db.createCollection()
.db.createCollection()
中指定encryptedFields
选项来创建索引。
If your MongoDB instance enforces the encryption of specific fields, any client performing Queryable Encryption with explicit encryption must encrypt those fields as specified. To learn how to set up server-side Queryable Encryption enforcement, see Field Encryption and Queryability.如果您的MongoDB实例强制对特定字段进行加密,则任何使用显式加密执行可查询加密客户端都必须按照指定对这些字段进行加密。要了解如何设置服务器端可查询加密强制,请参阅字段加密和可查询性。
Learn More了解更多信息
To learn more about Key Vault collections, Data Encryption Keys, and Customer Master Keys, see Keys and Key Vaults.要了解有关键库集合、数据加密键和客户主键的详细信息,请参阅键和键库。
To learn more about KMS providers and 要了解有关KMS提供程序和kkmsProviders
objects, see KMS Providers.msProviders
对象的详细信息,请参阅KMS提供器。