Skip to content

Privatebin

cyvax edited this page May 23, 2026 · 1 revision

Privatebin - camelCase client

The primary client. All setter methods return $this for fluent chaining. A static init() factory supports PHP 8 named arguments.

use Cyvax\Clients\Privatebin;

Creating an instance

Constructor

$client = new Privatebin();

Optionally pass an array of options to override defaults:

$client = new Privatebin([
    'url' => 'https://privatebin.net/',
    'expire' => '1hour',
    'compression' => 'none',
]);

See Advanced for custom HTTP client and encryptor injection.

Static factory (PHP 8+)

$client = Privatebin::init(
    url: 'https://privatebin.net/',
    text: 'Hello!',
    expire: '1hour',
    formatter: 'markdown',
    compression: 'none',
    discussion: false,
    burn: false,
    debug: false,
    sslVerify: true,
);

Posting a paste

One-shot

$result = (new Privatebin())
    ->setUrl('https://privatebin.net/')
    ->setText('Hello, world!')
    ->setExpire('1day')
    ->encodeAndPost();

Two-step (encode then post)

Useful when you need access to the encrypted payload before posting.

$client = (new Privatebin())
    ->setUrl('https://privatebin.net/')
    ->setText('Hello, world!');

$encoded = $client->encode();
// $encoded['b58']  - Base58 decryption key
// $encoded['data'] - encrypted payload

$result = $client->post($encoded);

Return value

Both encodeAndPost() and post() return:

[
    'requests_result' => object {
        'status' => 0,       // 0 = success
        'id' => 'abc123',    // paste ID
        'url' => '/?abc123',
    },
    'b58' => 'Base58EncodedKey', // decryption key
]

Reading a paste

Fetch and decrypt in one call

$decrypted = (new Privatebin())
    ->setUrl('https://privatebin.net/')
    ->fetchAndDecrypt('abc123', 'Base58EncodedKey');

Two-step (fetch then decrypt)

$client = (new Privatebin())->setUrl('https://privatebin.net/');

$raw = $client->fetch('abc123');
$decrypted = $client->decrypt($raw, 'Base58EncodedKey');

With a password

$decrypted = (new Privatebin())
    ->setUrl('https://privatebin.net/')
    ->fetchAndDecrypt('abc123', 'Base58EncodedKey', 'my-password');

Return value

[
    'paste' => 'Hello, world!',
    'attachment' => null,       // or 'data:text/plain;base64,…'
    'attachment_name' => null,  // or 'file.txt'
]

Setters

Method Parameter Default Notes
setUrl(string $url) URL of the PrivateBin instance https://paste.i2pd.xyz/
setText(string $text) Paste body ''
setPassword(string $password) Additional password required to decrypt the paste null
setExpire(string $expire, bool $bypass = false) Expiry string '1day' See valid values below
setFormatter(string $formatter, bool $bypass = false) Formatter 'plaintext' See valid values below
setCompression(string $compression) Compression mode ('zlib' or 'none') 'zlib' Requires ext-zlib when using 'zlib'
setDiscussion(bool $discussion) Enable comments false Disables burn if true
setBurn(bool $burn) Burn after reading false Disables discussion if true
setAttachment(string $fileLocation, ?string $filename) File path - Throws PrivatebinException if file cannot be read
setDebug(bool $debug) Print verbose encryption and request debug output false
setSslVerify(bool $sslVerify) Verify SSL certificates true Disable only for local or self-signed instances

Attachments

After decryption, the attachment key contains a data URI (data:mime/type;base64,…) and attachment_name contains the filename.

Valid expire values

5min · 10min · 1hour · 1day · 1week · 1month · 1year · never

Pass $bypass = true to use a custom value not in this list.

Valid formatter values

plaintext · syntaxhighlighting · markdown

Pass $bypass = true to use a custom value not in this list.


Exceptions

All methods that communicate with the server or perform encryption may throw Cyvax\Exceptions\PrivatebinException. See API Reference - Exceptions for the full matrix.

Full example

use Cyvax\Clients\Privatebin;

$result = (new Privatebin())
    ->setUrl('https://privatebin.net/')
    ->setText('# Hello')
    ->setFormatter('markdown')
    ->setExpire('1hour')
    ->setPassword('secret')
    ->setCompression('zlib')
    ->encodeAndPost();

$id = $result['requests_result']->id;
$key = $result['b58'];

$decrypted = (new Privatebin())
    ->setUrl('https://privatebin.net/')
    ->fetchAndDecrypt($id, $key, 'secret');

echo $decrypted['paste']; // '# Hello'

Clone this wiki locally