-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid using ASCII secret key in examples (#17)
- Loading branch information
Showing
1 changed file
with
13 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
|
@@ -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); | ||
|
||
|
@@ -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 */ | ||
|