KeyVault.createKey()
KeyVault.createKey(keyManagementService, customerMasterKey, ["keyAltName"])
Adds a data encryption key to the key vault associated to the database connection. クライアントサイドのフィールド レベル暗号化 uses data encryption keys for supporting encryption and decryption of field values.
次の値を返します。 The UUID
unique identifier of the created data encryption key.
互換性
このコマンドは、次の環境でホストされている配置で使用できます。
MongoDB Atlas はクラウドでの MongoDB 配置のためのフルマネージド サービスです
MongoDB Enterprise: サブスクリプションベースの自己管理型 MongoDB バージョン
MongoDB Community: ソースが利用可能で、無料で使用できる自己管理型の MongoDB のバージョン
構文
createKey()
の構文は次のとおりです。
keyVault = db.getMongo().getKeyVault() keyVault.createKey( keyManagementService, customerMasterKey, [ "keyAltName" ] )
Parameter | タイプ | 説明 |
---|---|---|
| string | 必須 The Key Management Service (KMS) to use for retrieving the Customer Master Key (CMK). Accepts the following parameters:
If the |
| 文字列またはドキュメント | The Customer Master Key (CMK) to use for encrypting the data
encryption key. Required if Provide the CMK as follows depending on your KMS provider:
This parameter has no effect if |
| array of strings | 任意 The alternative name for the data encryption key. Use
The |
| ドキュメント | 任意 A document that specifies options for the new key.
|
動作
データベース接続にクライアント側のフィールドレベル暗号化を構成する必要があります
mongosh
クライアント側のフィールド レベル暗号化メソッドでは、クライアント側のフィールド レベル暗号化が有効になっているデータベース接続が必要です。現在のデータベース接続がクライアント側のフィールド レベル暗号化を有効にして開始されなかった場合、次のいずれかが発生します。
Mongo()
必要なクライアント側のフィールドレベル暗号化オプションとの接続を確立するには、mongosh
から コンストラクターを使用します。Mongo()
メソッドは、CMK(Customer Master Key)管理のために次のKMS ( KMS )プロバイダーをサポートしています。or
必要なオプションとの接続を確立するには、
mongosh
コマンドライン オプションを使用します。 コマンドライン オプションは、CMK 管理用のAmazon Web Services KMSプロバイダーのみをサポートしています。
例
The following example is intended for rapid evaluation of
client-side field level encryption. For specific examples of using
KeyVault.createKey()
with each supported
KMS provider, see
Create a Data Key.
暗号化されたクライアントの作成
データベース接続を作成するには、クライアント側のフィールドレベル暗号化オプションが構成されたMongo()
コンストラクターを使用します。 mongodb://myMongo.example.net
URI を、ターゲットクラスターの接続string URIに置き換えます。
encryptedClient = Mongo( "mongodb://myMongo.example.net:27017/?replSetName=myMongo", autoEncryptionOpts )
Retrieve the keyVault
object and
use the KeyVault.createKey()
method to
create a new data encryption key using the locally managed key:
keyVault = encryptedClient.getKeyVault() keyVault.createKey("local", ["data-encryption-key"])
If successful, createKey()
returns the UUID
of
the new data encryption key. To retrieve the new data encryption
key document from the key vault, either:
使用
getKey()
to retrieve the created key byUUID
.または
使用
getKeyByAltName()
to retrieve the key by its alternate name.