PHP code example of devjack / encrypted-content-encoding
1. Go to this page and download the library: Download devjack/encrypted-content-encoding library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
devjack / encrypted-content-encoding example snippets
use Base64Url\Base64Url as b64;
$message = "I am the walrus";
$encoded = RFC8188::rfc8188_encode(
$message, // plaintext
b64::decode("yqdlZ-tYemfogSmv7Ws5PQ"), // encryption key
null, // key ID
123 // record size.
);
$decoded = RFC8188::rfc8188_decode(
$encoded, // data to decode
function($keyid) { return b64::decode('yqdlZ-tYemfogSmv7Ws5PQ'); }
);
$this->assertEquals($message, $decoded);
use DevJack\EncryptedContentEncoding\RFC8188;
use DevJack\EncryptedContentEncoding\Exception\EncryptionKeyNotFound;
use Base64Url\Base64Url as b64;
class MockKeyLookupProvider {
protected $keys = [];
public function addKey($key, $keyid='') {
$this->keys[$keyid] = $key;
}
public function __invoke($keyid) {
if (in_array($keyid, array_keys($this->keys))) {
return $this->keys[$keyid];
}
throw new EncryptionKeyNotFound("Encryption key not found.");
}
}
$encoded = b64::decode("uNCkWiNYzKTnBN9ji3-qWAAAABkCYTHOG8chz_gnvgOqdGYovxyjuqRyJFjEDyoF1Fvkj6hQPdPHI51OEUKEpgz3SsLWIqS_uA");
$keyProvider = new MockKeyLookupProvider();
$keyProvider->addKey(b64::decode("BO3ZVPxUlnLORbVGMpbT1Q"), 'a1');
$decoded = RFC8188::rfc8188_decode(
$encoded, // data to decode
$keyProvider
);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.