Skip to content
cyvax edited this page May 23, 2026 · 6 revisions

Privatebin_PHP

A PHP client library for PrivateBin

Requirements

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.


Installation

composer require cyvax/privatebin_php

Clients

The 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.


Quick Start

Post a paste

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)

Fetch and decrypt a paste

$decrypted = (new Privatebin())
    ->setUrl('https://privatebin.net/')
    ->fetchAndDecrypt($result['requests_result']->id, $result['b58']);

echo $decrypted['paste']; // 'Hello, world!'

With a password

$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'
    );

Pages

Clone this wiki locally