Skip to content

Commit

Permalink
Avoid using ASCII secret key in examples (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
tuupola authored May 31, 2021
1 parent d60e776 commit 10ca91a
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,24 @@ address. You also must provide a 32 byte secret key. The key is used for encrypt
```php
use Branca\Branca;

$branca = new Branca("supersecretkeyyoushouldnotcommit");
$key = random_bytes(32);
$branca = new Branca($key);

$payload = "[email protected]";
$token = $branca->encode($payload);
/* hGgg0dPSseaUPZqGloWlDGb2i8hb6iamFBIQaatgYDRhEuaXyByaX0nzmyQk1WYAuSBEMWpB20Z1dENLFItwf1 */

$decoded = $branca->decode($token); /* [email protected] */
$decoded = $branca->decode($token);
/* [email protected] */
```

Sometimes you might prefer JSON.

```php
use Branca\Branca;

$branca = new Branca("supersecretkeyyoushouldnotcommit");
$key = random_bytes(32);
$branca = new Branca($key);

$payload = json_encode(["scope" => ["read", "write", "delete"]]);
$token = $branca->encode($payload);
Expand Down Expand Up @@ -85,7 +89,9 @@ use MessagePack\MessagePack;
use MessagePack\Packer;
use MessagePack\BufferUnpacker;

$branca = new Branca("supersecretkeyyoushouldnotcommit");
$key = random_bytes(32);
$branca = new Branca($key);

$payload = (new Packer)->pack(["scope" => ["read", "write", "delete"]]);
$token = $branca->encode($payload);

Expand Down Expand Up @@ -118,7 +124,9 @@ Branca token includes a timestamp when it was created. When decoding you can opt
```php
use Branca\Branca;

$branca = new Branca("supersecretkeyyoushouldnotcommit");
$key = hex2bin("73757065727365637265746b6579796f7573686f756c646e6f74636f6d6d6974");
$branca = new Branca($key);

$token = "1jJDJOEeG2FutA8g7NAOHK4Mh5RIE8jtbXd63uYbrFDSR06dtQl9o2gZYhBa36nZHXVfiGFz";

print $branca->timestamp($token); /* 123206400 */
Expand Down

0 comments on commit 10ca91a

Please sign in to comment.