兼容性
此命令可用于以下环境中托管的部署:
- MongoDB Atlas:用于云中 MongoDB 部署的完全托管服务
MongoDB Enterprise:基于订阅、自我管理的 MongoDB 版本
MongoDB Community:源代码可用、免费使用且可自行管理的 MongoDB 版本
语法
getKey() 通过以下语法实现:
keyVault = db.getMongo().getKeyVault() keyVault.getKey(UUID("<UUID String>"))
The UUID is a BSON binary data object with subtype 4.
行为
需要在数据库连接上配置客户端字段级加密
The mongosh ClientEncryption methods require a database connection with in-use encryption enabled. If the current database connection was not initiated with in-use encryption enabled, either:
Use the
mongoshcommand line options to establish a connection with the required options. The command line options only support the Amazon Web Services KMS provider for CMK management.
例子
以下示例使用本地托管的 KMS进行客户端字段级加密配置。
2
3
Retrieve the keyVault object and use the KeyVault.getKey() to retrieve a data encryption key using its UUID:
keyVault = encryptedClient.getKeyVault() keyVault.getKey(UUID("b4b41b33-5c97-412e-a02b-743498346079"))
getKey() 返回数据加密密钥,输出类似于以下内容:
{ "_id" : UUID("b4b41b33-5c97-412e-a02b-743498346079"), "keyMaterial" : BinData(0,"E+0jZKzA4YuE1lGmSVIy2mivqH4JxFo0yFATdxYX/s0YtMFsgVXyu7Bbn4IQ2gn7F/9JAPJFOxdQc5lN3AR+oX33ewVZsd63f3DN1zzcukqdR2Y+EeO7ekRxyRjdzMaNNrBNIv9Gn5LEJgWPSYkG8VczF7cNZnc1YmnR0tuDPNYfm0J7dCZuZUNWW3FCGRcdFx6AlXiCtXKNR97hJ216pQ=="), "creationDate" : ISODate("2021-03-16T18:22:43.733Z"), "updateDate" : ISODate("2021-03-16T18:22:43.733Z"), "status" : 0, "version" : Long(0), "masterKey" : { "provider" : "local" }, "keyAltNames" : [ "alpha" ] }