https://github.com/hernandev/zodium
Zodium: OOP wrapper for PHP 7.2+ Sodium Extension (libsodium).
https://github.com/hernandev/zodium
Last synced: about 1 year ago
JSON representation
Zodium: OOP wrapper for PHP 7.2+ Sodium Extension (libsodium).
- Host: GitHub
- URL: https://github.com/hernandev/zodium
- Owner: hernandev
- License: mit
- Created: 2018-04-22T18:10:30.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2018-04-23T07:34:44.000Z (about 8 years ago)
- Last Synced: 2025-02-15T07:38:48.371Z (over 1 year ago)
- Language: C
- Homepage:
- Size: 190 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# Zodium
**Zodium** is an object-oriented wrapper for the `libsodium` bindings of PHP.
The name **Z**odium is due the fact of this extension being developed with [Zephir](https://zephir-lang.com/).
The original [sodium](https://github.com/jedisct1/libsodium-php) extension is still required, Zodium does not
bind the C library, this extension is a wrapper for the already existing, non-OOP extension.
#### Usage:
The library aims to be really easy to use.
##### Hashing:
```php
hash('foo');
// string(64) "93a0e84a8cdd416626...
// generate a hashing key.
$key = GenericHash::generateKey();
// string(64) "62009feb496f0...
// start a new hasher with the hashing key.
$hasher = new GenericHasher($key);
$hash = $hasher->hash('foo');
// string(64) "714ee3a37cf69bb3aee17...
// start a custom length hash output instance.
$hasher = new GenericHash($key, 64);
$hash = $hasher->hash('foo');
// string(128) "d94315288e268d813e...
// multi-part signature..
$hasher->add("part1");
$hasher->add("part2");
// get the final hash from the parts included.
$hash = $hasher->hash();
```
##### AEAD:
```php
setSecretKey(Cipher::generateSecretKey());
// encrypt the secret data with some associated public data.
$encryptedPayload = $cipher->encrypt('message', 'associated-data');
// decrypt the original message from the payload.
$original = $cipher->decrypt($encryptedPayload);
```
##### SecretBox:
```php
encrypt('some-data-as-string');
// encode the payload for transmission or storage:
$payloadString = $payload->encode();
// reverse the payload from string into instance.
$payload = EncryptedPayload::decode($payloadString);
// decrypt.
$originalData = $box->decrypt($payload);
// extras:
// you can encrypt any serializable value on PHP.
$payload = $box->encrypt(new Datetime());
// the value will be unserialized back on the original type!.
$dateTimeInstance = $box->decrypt($payload);
```
#### Roadmap:
Current features to be included are:
- Constant-time helpers and safe evaluation of sensitive values.
- Public-key Encryption.
- Stand-alone message authentication.
- Bind Zephir optimizers to calls on the libsodium directly.
- Documentation
- .phpt tests.