라이브러리
[PHP] MongoDBDriverClientEncryption::getKey - 키 문서를 가져옵니다.
MongoDB Driver Client Encryption
MongoDB Driver Client Encryption은 MongoDB 클라이언트에서 데이터를 암호화하고, MongoDB 서버에서 데이터를 암호화하기 전에 암호화하는 데 사용됩니다. Client Encryption은 MongoDB 클라이언트에서 데이터를 암호화하고, MongoDB 서버에서 데이터를 암호화하기 전에 암호화하는 데 사용됩니다.
getKey() 메서드
`getKey()` 메서드는 Client Encryption에서 사용하는 키를 반환합니다. 이 키는 MongoDB 서버에서 데이터를 암호화하기 전에 암호화하는 데 사용됩니다.
# getKey() 메서드의 매개변수
`getKey()` 메서드는 다음과 같은 매개변수를 받습니다.
* `keyId`: 키 ID를 지정합니다. 키 ID는 Client Encryption에서 사용하는 키를 식별하는 고유한 문자열입니다.
* `keyAltName`: 키 대체 이름을 지정합니다. 키 대체 이름은 Client Encryption에서 사용하는 키를 식별하는 고유한 문자열입니다.
# getKey() 메서드의 반환값
`getKey()` 메서드는 Client Encryption에서 사용하는 키를 반환합니다. 이 키는 MongoDB 서버에서 데이터를 암호화하기 전에 암호화하는 데 사용됩니다.
# 예제
다음 예제는 `getKey()` 메서드를 사용하는 방법을 보여줍니다.
#hostingforum.kr
php
use MongoDBClientEncryption;
use MongoDBBSONBinary;
use MongoDBBSONUTCDateTime;
// Client Encryption 인스턴스 생성
$clientEncryption = new ClientEncryption(
[
'key' => new Binary(
'your-key-here',
Binary::TYPE_BINARY
),
'keyAltName' => 'your-key-alt-name-here',
'keyId' => 'your-key-id-here',
'collection' => 'your-collection-here',
'collectionName' => 'your-collection-name-here',
'kmsProvider' => 'your-kms-provider-here',
'kmsProjectId' => 'your-kms-project-id-here',
'kmsRegion' => 'your-kms-region-here',
'kmsKeyRing' => 'your-kms-key-ring-here',
'kmsKey' => 'your-kms-key-here',
'kmsLocation' => 'your-kms-location-here',
],
(new MongoDBClient)->selectDatabase('your-database-here')
);
// getKey() 메서드 호출
$key = $clientEncryption->getKey('your-key-id-here', 'your-key-alt-name-here');
// 키를 사용하여 데이터 암호화
$data = [
'name' => 'John Doe',
'email' => 'john.doe@example.com',
];
$encryptedData = $clientEncryption->encrypt($data);
// 암호화된 데이터를 MongoDB 서버에 저장
$db = (new MongoDBClient)->selectDatabase('your-database-here');
$collection = $db->selectCollection('your-collection-here');
$collection->insertOne($encryptedData);
이 예제는 Client Encryption에서 사용하는 키를 가져오고, 데이터를 암호화하고, 암호화된 데이터를 MongoDB 서버에 저장하는 방법을 보여줍니다.
-
- 나우호스팅 @pcs8404
-
호스팅포럼 화이팅!
댓글목록
등록된 댓글이 없습니다.