-
Notifications
You must be signed in to change notification settings - Fork 3
Privatebin
The primary client. All setter methods return $this for fluent chaining. A static init() factory supports PHP 8 named arguments.
use Cyvax\Clients\Privatebin;$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.
$client = Privatebin::init(
url: 'https://privatebin.net/',
text: 'Hello!',
expire: '1hour',
formatter: 'markdown',
compression: 'none',
discussion: false,
burn: false,
debug: false,
sslVerify: true,
);$result = (new Privatebin())
->setUrl('https://privatebin.net/')
->setText('Hello, world!')
->setExpire('1day')
->encodeAndPost();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);Both encodeAndPost() and post() return:
[
'requests_result' => object {
'status' => 0, // 0 = success
'id' => 'abc123', // paste ID
'url' => '/?abc123',
},
'b58' => 'Base58EncodedKey', // decryption key
]$decrypted = (new Privatebin())
->setUrl('https://privatebin.net/')
->fetchAndDecrypt('abc123', 'Base58EncodedKey');$client = (new Privatebin())->setUrl('https://privatebin.net/');
$raw = $client->fetch('abc123');
$decrypted = $client->decrypt($raw, 'Base58EncodedKey');$decrypted = (new Privatebin())
->setUrl('https://privatebin.net/')
->fetchAndDecrypt('abc123', 'Base58EncodedKey', 'my-password');[
'paste' => 'Hello, world!',
'attachment' => null, // or 'data:text/plain;base64,…'
'attachment_name' => null, // or 'file.txt'
]| 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 |
After decryption, the attachment key contains a data URI (data:mime/type;base64,…) and attachment_name contains the filename.
5min · 10min · 1hour · 1day · 1week · 1month · 1year · never
Pass $bypass = true to use a custom value not in this list.
plaintext · syntaxhighlighting · markdown
Pass $bypass = true to use a custom value not in this list.
All methods that communicate with the server or perform encryption may throw Cyvax\Exceptions\PrivatebinException. See API Reference - Exceptions for the full matrix.
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'