KeyVault.createKey(keyManagementService, customerMasterKey, ["keyAltName"])データベース接続に関連付けられたキーヴォールトにデータ暗号化キーを追加します。 クライアント側のフィールドレベル暗号化は、フィールド値の暗号化と復号化をサポートするためにデータ暗号化キーを使用します。
次の値を返します。 作成されたデータ暗号化キーの
UUID一意の識別子。
互換性
このコマンドは、次の環境でホストされている配置で使用できます。
- MongoDB Atlas はクラウドでの MongoDB 配置のための完全管理サービスです
MongoDB Enterprise: サブスクリプションベースの自己管理型 MongoDB バージョン
MongoDB Community: ソースが利用可能で、無料で使用できる自己管理型の MongoDB のバージョン
構文
createKey() の構文は次のとおりです。
keyVault = db.getMongo().getKeyVault() keyVault.createKey( keyManagementService, customerMasterKey, [ "keyAltName" ] )
Parameter | タイプ | 説明 |
|---|---|---|
| string | 必須 CMK(Customer Master Key)の取得に使用するKMS ( KMS )。 次のパラメータを受け入れます。
|
| 文字列またはドキュメント | データ暗号化キーの暗号化に使用する CMK(Customer Master Key)。 KMS プロバイダーに応じて、次のように CMK を指定します。
このパラメータは、 |
| 文字列の配列 | 任意 データ暗号化キーの別名。 特定のデータ暗号化キーを見つけやすくするには、またはコメントに類似するものとして メソッドは、 |
| ドキュメント | 任意 新しいキーのオプションを指定するドキュメント。
|
動作
データベース接続にクライアント側のフィールドレベル暗号化を構成する必要があります
The mongosh client-side field level encryption methods require a database connection with client-side field level encryption enabled. If the current database connection was not initiated with client-side field level 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.
例
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()を使用して、UUIDによって作成されたキーを取得します。または
別名でキーを検索するには、
getKeyByAltName()を使用します。