Skip to content

Instantly share code, notes, and snippets.

@paragonie-scott
Last active November 18, 2017 21:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paragonie-scott/d37475b0bfc9bb437f0786188f2e9e2c to your computer and use it in GitHub Desktop.
Save paragonie-scott/d37475b0bfc9bb437f0786188f2e9e2c to your computer and use it in GitHub Desktop.
Chronicle Test Client
<?php
namespace ChronicleClient;
use GuzzleHttp\Client;
use ParagonIE\Chronicle\Chronicle;
use ParagonIE\ConstantTime\Base64UrlSafe;
use ParagonIE\Sapient\Adapter\Guzzle;
use ParagonIE\Sapient\CryptographyKeys\{
SigningPublicKey,
SigningSecretKey
};
use ParagonIE\Sapient\Sapient;
require_once 'vendor/autoload.php';
$chronicle = \json_decode(\file_get_contents('server.json'), true);
$file = 'message.txt';
$contents = \file_get_contents($file);
if (empty($contents)) {
exit(255);
}
$http = new Client();
$sapient = new Sapient(new Guzzle($http));
$request = $sapient->createSignedRequest(
'POST',
$chronicle['url'] . '/chronicle/publish',
$contents,
new SigningSecretKey(
Base64UrlSafe::decode($chronicle['my-secret-key'])
)
)->withAddedHeader(
'Chronicle-Client-Key-ID',
$chronicle['client-id']
);
$response = $http->send($request);
$decoded = $sapient->decodeSignedJsonResponse(
$response,
new SigningPublicKey(
Base64UrlSafe::decode($chronicle['chronicle-public-key'])
)
);
var_dump($decoded);
{
"require": {
"paragonie/sapient": "^1.0",
"guzzlehttp/guzzle": "^6"
}
}
{
"url": "https://chronicle-public-test.paragonie.com",
"client-id": "",
"my-secret-key": "",
"my-public-key": "",
"chronicle-public-key": "3BK4hOYTWJbLV5QdqS-DFKEYOMKd-G5M9BvfbqG1ICI="
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment