Skip to content

PrivatebinSnakeCase

cyvax edited this page May 23, 2026 · 3 revisions

PrivatebinSnakeCase - snake_case client

A snake_case API wrapper over the same encryption core used by Privatebin.

Implements PrivatebinSnakeCaseClientInterface.

Use this client if you prefer snake_case naming or need the \Cyvax\PrivatebinPHP backward-compatibility alias.

use Cyvax\Clients\PrivatebinSnakeCase;

Note

Backward-compatibility alias - \Cyvax\PrivatebinPHP is an alias for this class.

Code written against the original library continues to work without changes.


Creating an instance

Constructor

$client = new PrivatebinSnakeCase();

Optionally pass an array of options:

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

See Advanced for custom HTTP client and encryptor injection.


Posting a paste

$result = (new PrivatebinSnakeCase())
    ->set_url('https://privatebin.net/')
    ->set_text('Hello, world!')
    ->set_expire('1day')
    ->encode_and_post();

Two-step version:

$client = (new PrivatebinSnakeCase())
    ->set_url('https://privatebin.net/')
    ->set_text('Hello, world!');

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

Return value

[
    'requests_result' => object {
        'status' => 0,
        'id' => 'abc123',
        'url' => '/?abc123',
    },
    'b58' => 'Base58EncodedKey',
]

Reading a paste

$decrypted = (new PrivatebinSnakeCase())
    ->set_url('https://privatebin.net/')
    ->fetch_and_decrypt('abc123', 'Base58EncodedKey');

With a password:

$decrypted = (new PrivatebinSnakeCase())
    ->set_url('https://privatebin.net/')
    ->fetch_and_decrypt('abc123', 'Base58EncodedKey', 'my-password');

Two-step fetch and decrypt:

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

Return value

[
    'paste' => 'Hello, world!',
    'attachment' => null,
    'attachment_name' => null,
]

Setters

Method Parameter Default Notes
set_url(string $url) URL of the PrivateBin instance https://paste.i2pd.xyz/
set_text(string $text) Paste body ''
set_password(string $password) Additional password required to decrypt the paste null
set_expire(string $expire, bool $bypass = false) Expiry string '1day'
set_formatter(string $formatter, bool $bypass = false) Formatter 'plaintext'
set_compression(string $compression) 'zlib' or 'none' 'zlib' Requires ext-zlib when using 'zlib'
set_discussion(bool $discussion) Enable comments false Disables burn if true
set_burn(bool $burn) Burn after reading false Disables discussion if true
set_attachment(string $file_location, ?string $filename) File path - Throws PrivatebinException if file cannot be read
set_debug(bool $debug) Print debug output false
set_ssl_verify(bool $ssl_verify) Verify SSL certificates true Disable only for local or self-signed instances

See Privatebin or your intended instance for valid expire, formatter, and compression values.

Attachments

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

See Advanced for implementing custom HTTP clients and encryptors.

Backward-compatibility alias

$client = new \Cyvax\PrivatebinPHP();
$result = $client
    ->set_url('https://privatebin.net/')
    ->set_text('Hello!')
    ->encode_and_post();

$decrypted = (new \Cyvax\PrivatebinPHP())
    ->set_url('https://privatebin.net/')
    ->fetch_and_decrypt($result['requests_result']->id, $result['b58']);

Note

New projects should prefer using Cyvax\Clients\PrivatebinSnakeCase instead of that BC alias.

The alias is provided for compatibility with older versions of the library, and override some functions.

(e.g. eat the exception thrown by paste() and return the raw response instead, to match the original library's behavior).


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\PrivatebinSnakeCase;

$result = (new PrivatebinSnakeCase())
    ->set_url('https://privatebin.net/')
    ->set_text('Hello, world!')
    ->set_expire('1hour')
    ->set_formatter('plaintext')
    ->set_compression('zlib')
    ->set_discussion(false)
    ->set_burn(false)
    ->encode_and_post();

$decrypted = (new PrivatebinSnakeCase())
    ->set_url('https://privatebin.net/')
    ->fetch_and_decrypt($result['requests_result']->id, $result['b58']);

echo $decrypted['paste'];

Clone this wiki locally