라이브러리

[PHP] MongoDBDriverClientEncryption::decrypt - 값 암호 해독




MongoDB Driver Client Encryption

MongoDB Driver Client Encryption은 MongoDB의 클라이언트 측 암호화 기능입니다. 이 기능을 사용하면 클라이언트에서 데이터를 암호화하고 MongoDB에 저장할 수 있습니다. MongoDB Driver Client Encryption은 MongoDB 3.6 이상에서 지원됩니다.

MongoDB Driver Client Encryption 사용하기

MongoDB Driver Client Encryption을 사용하기 위해서는 먼저 MongoDB Driver를 설치해야 합니다. MongoDB Driver는 PHP로 작성된 MongoDB 클라이언트 라이브러리입니다.

설치

MongoDB Driver를 설치하기 위해서는 Composer를 사용할 수 있습니다. Composer는 PHP의 패키지 매니저입니다.

#hostingforum.kr
bash

composer require mongodb/mongodb



사용하기

MongoDB Driver Client Encryption을 사용하기 위해서는 먼저 ClientEncryption 객체를 생성해야 합니다. ClientEncryption 객체는 MongoDB Driver의 ClientEncryption 클래스를 사용하여 생성할 수 있습니다.

#hostingforum.kr
php

use MongoDBClientEncryption;

use MongoDBBSONBinary;

use MongoDBBSONUTCDateTime;



$mongo = new MongoDBClient('mongodb://localhost:27017');

$clientEncryption = $mongo->getClientEncryption();



암호화

ClientEncryption 객체를 사용하여 데이터를 암호화할 수 있습니다. 암호화할 데이터는 Binary 객체로 전달해야 합니다.

#hostingforum.kr
php

$data = new Binary('Hello, World!', Binary::TYPE_STRING);

$encryptedData = $clientEncryption->encrypt($data);



복호화

ClientEncryption 객체를 사용하여 암호화된 데이터를 복호화할 수 있습니다. 복호화할 데이터는 Binary 객체로 전달해야 합니다.

#hostingforum.kr
php

$decryptedData = $clientEncryption->decrypt($encryptedData);

echo $decryptedData->getData(); // Hello, World!



예제

다음은 MongoDB Driver Client Encryption을 사용하여 데이터를 암호화하고 복호화하는 예제입니다.

#hostingforum.kr
php

use MongoDBClientEncryption;

use MongoDBBSONBinary;

use MongoDBBSONUTCDateTime;



$mongo = new MongoDBClient('mongodb://localhost:27017');

$clientEncryption = $mongo->getClientEncryption();



$data = new Binary('Hello, World!', Binary::TYPE_STRING);

$encryptedData = $clientEncryption->encrypt($data);



$collection = $mongo->selectCollection('test', 'data');

$collection->insertOne(['encryptedData' => $encryptedData]);



$decryptedData = $clientEncryption->decrypt($encryptedData);

echo $decryptedData->getData(); // Hello, World!



참고

MongoDB Driver Client Encryption은 MongoDB 3.6 이상에서만 지원됩니다. 또한 ClientEncryption 객체를 생성하기 위해서는 MongoDB Driver의 ClientEncryption 클래스를 사용해야 합니다. ClientEncryption 클래스는 MongoDB Driver의 ClientEncryption 클래스를 상속합니다.
  • profile_image
    나우호스팅 @pcs8404 

    호스팅포럼 화이팅!

    댓글목록

    등록된 댓글이 없습니다.

  • 전체 10,077건 / 400 페이지

검색

게시물 검색