Recommend this page to a friend! |
![]() |
Info | ![]() |
![]() |
![]() |
Reputation | Support forum | Blog | Links |
Last Updated | Ratings | Unique User Downloads | Download Rankings | |||||
2025-05-07 (3 days ago) ![]() | Not enough user ratings | Total: 120 | All time: 9,510 This week: 560![]() |
Version | License | PHP version | Categories | |||
colloportus 1.0 | MIT/X Consortium ... | 7.1.2 | Cryptography, Security, PHP 7 |
Description | Author | |
This class can create a key, encrypt, decrypt data with sha-384. |
|
Please use Iridium security library instead.
Welcome to Colloportus, a password hashing and data encryption library! This library can be used for hashing passwords, as well as for encrypting data that needs to be decrypted afterwards. It wraps Bcrypt-SHA384 in Authenticated Encryption. A simplified fork of Password Lock by Paragon Initiative Enterprises. Integrates parts of Defuse PHP Encryption for authenticated symmetric-key encryption. Depends on Oirë Base64 for encoding binary data to a storable format.
Colloportus is a magical spell in the well-known Harry Potter series. It locks doors in a very hard-to-open way, and such a door is completely impossible to open for muggles, i.e., non-wizarding people. I decided to use this as a name for my simplified fork of PasswordLock.
The method names are also simplified: lock
, check
and flip
instead of HashAndEncrypt
, DecryptAndVerify
and RotateKey
.
Requires PHP 7.3 or later with mbString
and openSSL
enabled.
Install via Composer:
composer require oire/colloportus
Run ./vendor/bin/phpunit
in the projects directory.
If you want a version compatible with PHP 7.1.2, please install version 1 instead:
composer require "oire/colloportus ^1"
use Oire\Colloportus\Colloportus;
use Oire\Colloportus\Exception\ColloportusException;
// Actually you need to create a key beforehand and save it somewhere, for example, in a .env file
$key = Colloportus::createKey();
if (!empty($_POST['password'])) {
try {
$storeMe = Colloportus::lock($_POST['password'], $key);
} catch (ColloportusException $e) {
// Handle errors
}
}
if (!empty($_POST['password'])) {
try {
$verified = Colloportus::check($_POST['password'], $storeMe, $key);
} catch (ColloportusException $e) {
// Handle errors
}
if ($verified) {
// Success!
}
}
Note! Do not use this for passwords, they must not be back-decryptable. If you want to store a password, you must hash it (see above).
$data = 'Mischief managed!';
$encrypted = Colloportus::encrypt($data, $key);
$decrypted = Colloportus::decrypt($encrypted, $key);
var_export($decrypted === $data);
// => true
$newKey = Colloportus::createKey();
try {
$newHash = Colloportus::flip($storeMe, $key, $newKey);
} catch (ColloportusException $e) {
// Handle errors
}
Colloportus has various exceptions that are thrown when something fails:
* A generic ColloportusException
which is always safe to catch. All other exceptions inherit from it;
* EncryptionException
is thrown whenever data encryption fails;
* DecryptionException
is thrown whenever data decryption fails;
* PasswordException
is thrown whenever a password-related call fails;
* KeyException
is thrown when any key-related call fails.
All Colloportus methods are public and static, so no class instance is required. The methods are documented in the code comments, but their description is given below for rerefence.
We recommend to wrap every call in try...catch
since Colloportus throws ColloportusException
in case of errors.
All contributions are welcome. Please fork, make a feature branch, hack on the code, run tests, push your branch and send a pull-request.
Copyright © 2017-2021, Andre Polykanine also known as Menelion Elensúlë, The Magical Kingdom of Oirë. This software is licensed under an MIT license.
![]() |
File | Role | Description | ||
---|---|---|---|---|
![]() |
||||
![]() |
||||
![]() |
||||
![]() |
Data | Auxiliary data | ||
![]() |
Example | Example script | ||
![]() |
Data | Auxiliary data | ||
![]() |
Data | Auxiliary data | ||
![]() |
Lic. | License text | ||
![]() |
Data | Auxiliary data | ||
![]() |
Data | Auxiliary data | ||
![]() |
Doc. | Documentation |
The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page. |
![]() |
![]() | colloportus-2025-05-07.zip |
![]() | colloportus-2025-05-07.tar.gz |
![]() | Install with Composer |
Needed packages | ||
Class | Download | Why it is needed | Dependency |
---|---|---|---|
Oire Base64 | ![]() |
Needed to transform binary data into a storable form. | Required |
Version Control | Unique User Downloads | Download Rankings | |||||||||||||||
100% |
|
|
Applications that use this package |
If you know an application of this package, send a message to the author to add a link here.