Download the PHP package initphp/encryption without Composer

On this page you can find all versions of the php package initphp/encryption. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package encryption

initphp/encryption

Secure, modern symmetric encryption for PHP on top of OpenSSL and libsodium.

Latest Stable Version Total Downloads License PHP Version Require

Why

PHP's encryption primitives are powerful but unforgiving. Pick the wrong cipher, mix up IV and HMAC ordering, forget constant-time comparison, or hand libsodium a 14-byte "key" and you ship a vulnerability — or, more often, a silent failure that "works on my machine".

This package wraps ext-openssl and ext-sodium behind a small, opinionated API:

Requirements

Both extensions ship with mainstream PHP distributions, but the package only loads the one you actually instantiate — you can use one handler without the other being available.

Installation

Quickstart

The Sodium handler has the same surface:

Configuration

Every option is optional except key. Unknown keys are ignored. Keys are case-insensitive on input ('CIPHER' and 'cipher' are the same option).

Option Used by Default Description
key both required The user-supplied secret. Any non-empty string; the handler derives a key of the correct length internally.
cipher OpenSSL AES-256-CTR Any algorithm from openssl_get_cipher_methods().
algo OpenSSL SHA256 Any algorithm from hash_hmac_algos(). Used both for HKDF key derivation and for the HMAC tag.
blocksize Sodium 16 Block size for sodium_pad() / sodium_unpad(). Must be a positive integer.
serializer both 'json' One of 'json', 'php_serialize', 'php', 'serialize'. See Serialization.

Options can be set in three places, in order of precedence (highest wins):

Per-call options do not mutate the handler — they are merged into a fresh array for that single call only.

Serialization

encrypt() accepts mixed and round-trips the value through a serializer chosen via the serializer option. The flag is embedded in the ciphertext, so decrypt() always restores the original type without you having to track the choice yourself.

serializer value On-the-wire flag Behaviour
'json' (default) 0x00 Uses json_encode/json_decode with JSON_THROW_ON_ERROR. Safe: no PHP class is ever instantiated during decoding. Cannot carry raw binary bytes — use php_serialize if you need that.
'php_serialize', 'php', 'serialize' 0x01 Uses serialize()/unserialize() with ['allowed_classes' => false]. Round-trips scalars, arrays and binary strings; custom objects degrade to __PHP_Incomplete_Class on decode.

The PHP serializer is opt-in for one reason only: even though we always pass allowed_classes:false, the safer default lets you not have to think about object-injection vectors at all.

Writing a Custom Handler

Extend BaseHandler (not OpenSSL / Sodium — those are final) and implement encrypt() and decrypt():

BaseHandler gives you resolveOptions(), requireKey(), serializerFlag(), serializePayload() and unserializePayload() for free, so you only write the cryptographic glue.

Error Handling

Every failure path raises InitPHP\Encryption\Exceptions\EncryptionException (which extends \RuntimeException). A single catch covers everything:

Notable messages you may see:

Security Notes

Upgrading from 1.x

Version 2.0 is a hard reset of the public surface and the on-wire format:

A full migration walk-through lives in docs/08-migration-v1-to-v2.md (shipped with the package; see also the docs/ index).

Contributing

PRs are welcome. Please read CONTRIBUTING.md first — it covers the local quality gates (composer test, composer phpstan, composer cs-check) and the security-review process for changes touching the cryptographic primitives.

License

MIT — see LICENSE.


All versions of encryption with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package initphp/encryption contains the following files

Loading the files please wait ...