AI エージェント向け: ドキュメントインデックスは https://www.mongodb.com/ja-jp/docs/llms.txt で利用できます。すべてのページの markdown バージョンは、いずれかの URL パスに .md を追加することで利用できます。
Docs Menu

ClientEncryption.decryption.decryption()(mongoshメソッド)

ClientEncryption.decrypt(encryptedValue)

ClientEncryption.decrypt() decrypts the encryptionValue if the current database connection was configured with access to the Key Management Service (KMS) and key vault used to encrypt encryptionValue.

次の値を返します。

復号化された値。

このコマンドは、次の環境でホストされている配置で使用できます。

  • MongoDB Atlas: The fully managed service for MongoDB deployments in the cloud
  • MongoDB Enterprise: サブスクリプションベースの自己管理型 MongoDB バージョン

  • MongoDB Community: ソースが利用可能で、無料で使用できる自己管理型の MongoDB のバージョン

ClientEncryption.decrypt の構文は次のとおりです。

clientEncryption = db.getMongo().getClientEncryption()
clientEncryption.decrypt(encryptedValue)

は、encryptedValue クライアント側のフィールドレベル暗号化を使用して作成されたサブタイプbinary data 6を持つ オブジェクトである必要があります。

Read operations issued from a database connection configured with access to the correct Key Management Service (KMS) and Key Vault can automatically decrypt field values encrypted using ClientEncryption.encrypt(). Clients only need to use decrypt() to decrypt Binary subtype 6 values not stored within a document field.

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:

次の例では、クライアント側のフィールドレベル暗号化構成にローカルで管理されている KMS を使用しています。

1
  1. mongosh を起動する

    実行:

    mongosh --nodb

    --nodb は、データベースに接続しないことを意味します。

  2. キーstringの生成

    基本64 96バイトの string を生成する:

    const TEST_LOCAL_KEY = require("crypto").randomBytes(96).toString("base64")
  3. 暗号化オプション オブジェクトの作成

    クライアント側のフィールドレベル暗号化オプションオブジェクトを作成するには、前のステップのTEST_LOCAL_KEY string を使用します。

    var autoEncryptionOpts = {
    "keyVaultNamespace" : "encryption.__dataKeys",
    "kmsProviders" : {
    "local" : {
    "key" : BinData(0, TEST_LOCAL_KEY)
    }
    }
    }
  4. 暗号化されたクライアント オブジェクトの作成

    暗号化されたクライアントオブジェクトを作成するには、 Mongo()コンストラクターを使用します。 mongodb://myMongo.example.net URI を、ターゲットクラスターの接続string URIに置き換えます。 (例: )。

    encryptedClient = Mongo(
    "mongodb://myMongo.example.net:27017/?replSetName=myMongo",
    autoEncryptionOpts
    )
2

Retrieve the ClientEncryption object and use the ClientEncryption.decrypt() method to decrypt a value encrypted by ClientEncryption.encrypt().

clientEncryption = encryptedClient.getClientEncryption();
clientEncryption.decrypt(BinData(6,"AmTi2H3xaEk8u9+jlFNaLLkC3Q/+kmwDbbWrq+h9nuv9W+u7A5a0UnpULBNZH+Q21fAztPpU09wpKPrju9dKfpN1Afpj1/ZhFcH6LYZOWSBBOAuUNjPLxMNSYOOuITuuYWo="))

If successful, decrypt() returns the decrypted value:

"123-45-6789"

クライアント側のフィールドレベル暗号化を有効にして MongoDB 接続を開始する方法に関する詳細なドキュメントについては、 Mongo()を参照してください。

このページを評価