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 클라이언트 사이드 필드 수준 암호화 사용하여 생성된 하위 6 binary data 유형 의 객체 여야 합니다.
행동
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.
예시
다음 예에서는 클라이언트 사이드 필드 수준 암호화 구성을 위해 로컬로 managed 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() 를 참조하세요.