-
Notifications
You must be signed in to change notification settings - Fork 3
Home
A PHP client library for PrivateBin
| Requirement | Notes |
|---|---|
| PHP | >= 7.1 |
| ext-json | required |
| ext-openssl | required |
| ext-curl | required - (if using default HttpClient) |
| ext-gmp | optional - faster Base58 encoding/decoding |
| ext-zlib | optional - required for zlib compression (default) |
| ext-fileinfo | optional - accurate MIME type detection for attachments |
zlib compression is enabled by default. If ext-zlib is not installed, set compression to 'none' explicitly.
composer require cyvax/privatebin_phpThe library ships three clients. All share the same encryption core.
| Client | Style | PHP |
|---|---|---|
| Privatebin | Fluent camelCase | >= 7.1 |
| PrivatebinSnakeCase | Fluent snake_case | >= 7.1 |
| PrivatebinPipe | Functional pipe-style API | >= 8.5 |
A \Cyvax\PrivatebinPHP backward-compatibility alias maps to PrivatebinSnakeCase for projects written against older versions of the library.
All clients produce identical PrivateBin-compatible payloads and are fully interoperable, a paste created with one client can be decrypted with any other.
Note
PrivatebinPipe is designed for the PHP 8.5 |> pipe operator and is primarily intended for PHP 8.5+ environments.
The class itself remains compatible with older PHP versions because it internally uses closures only.
While these closures can still be invoked manually on older PHP versions, this is generally less readable.
On PHP versions without pipe support, using Privatebin or PrivatebinSnakeCase directly is recommended.
use Cyvax\Clients\Privatebin;
$result = (new Privatebin())
->setUrl('https://privatebin.net/')
->setText('Hello, world!')
->setExpire('1day')
->encodeAndPost();
// $result['requests_result']->id - paste ID
// $result['b58'] - decryption key (Base58)$decrypted = (new Privatebin())
->setUrl('https://privatebin.net/')
->fetchAndDecrypt($result['requests_result']->id, $result['b58']);
echo $decrypted['paste']; // 'Hello, world!'$result = (new Privatebin())
->setUrl('https://privatebin.net/')
->setText('Secret message')
->setPassword('my-password')
->encodeAndPost();
$decrypted = (new Privatebin())
->setUrl('https://privatebin.net/')
->fetchAndDecrypt(
$result['requests_result']->id,
$result['b58'],
'my-password'
);