ClientEncryption.decrypt(encryptedValue)ClientEncryption.decrypt()decrypts theencryptionValueif the current database connection was configured with access to the Key Management Service (KMS) and key vault used to encryptencryptionValue.次の値を返します。 復号化された値。
互換性
このコマンドは、次の環境でホストされている配置で使用できます。
- 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:
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 を使用しています。
暗号化された接続の作成
mongosh を起動する
実行:
mongosh --nodb --nodbは、データベースに接続しないことを意味します。キーstringの生成
基本64 96バイトの string を生成する:
const TEST_LOCAL_KEY = require("crypto").randomBytes(96).toString("base64") 暗号化オプション オブジェクトの作成
クライアント側のフィールドレベル暗号化オプションオブジェクトを作成するには、前のステップの
TEST_LOCAL_KEYstring を使用します。var autoEncryptionOpts = { "keyVaultNamespace" : "encryption.__dataKeys", "kmsProviders" : { "local" : { "key" : BinData(0, TEST_LOCAL_KEY) } } } 暗号化されたクライアント オブジェクトの作成
暗号化されたクライアントオブジェクトを作成するには、
Mongo()コンストラクターを使用します。mongodb://myMongo.example.netURI を、ターゲットクラスターの接続string URIに置き換えます。 (例: )。encryptedClient = Mongo( "mongodb://myMongo.example.net:27017/?replSetName=myMongo", autoEncryptionOpts )
データの復号化
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()を参照してください。