<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
paragonie / ciphersweet-provider-aws-kms example snippets
use Aws\Kms\KmsClient;
use ParagonIE\Certainty\RemoteFetch;
use ParagonIE\CipherSweet\Backend\BoringCrypto;
use ParagonIE\CipherSweet\KeyProvider\KmsKeyProvider;
// Recommended: always use the latest CACert bundle
$remoteFetch = new RemoteFetch('/path/to/cacert-dir');
$latestBundle = $remoteFetch->getLatestBundle()->getFilePath();
$keyID = ''; /* get this from KMS */
$kmsClient = new KmsClient([
'profile' => 'default',
'region' => 'us-east-1',
'http' => ['verify' => $latestBundle]
]);
// Recommended: Use encryption context for your apps
$encryptionContext = [
'app' => 'foo.example.com'
];
$newKey = KmsKeyProvider::generate(
$kmsClient,
new BoringCrypto(), // Your backend goes here
$keyID,
$encryptionContext
);
// Save this somewhere so you can reuse it:
$edk = $newKey->getEncryptedDataKey();
// Moving forward, you can simply instantiate your key provider like so:
$provider = new KmsKeyProvider(
$kmsClient,
new BoringCrypto(), // Your backend goes here
$keyID,
$encryptionContext,
$edk
);
/**
* @var \ParagonIE\CipherSweet\KeyProvider\MultiTenantKmsKeyProvider $multiPro
* @var \ParagonIE\CipherSweet\KeyProvider\KmsKeyProvider $provider
* @var \Psr\SimpleCache\CacheInterface $yourCache
*/
// This will pass $yourCache to all KmsKeyProviders managed by this multi-tenant provider:
$multiPro->setDataKeyCache($yourCache);
// For only one single-tenant provider:
$provider->setDataKeyCache($yourCache);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.