eloquent / lockbox
This package is abandoned and no longer maintained.
No replacement package was suggested.
Simple, strong encryption.
0.2.0
2013-09-03 11:29 UTC
Requires
- php: >=5.3
- ext-mcrypt: *
- ext-openssl: *
- icecave/isolator: ~2
Requires (Dev)
- eloquent/asplode: ~1
- eloquent/liberator: ~1
- icecave/archer: 1.0.0-alpha.2
This package is auto-updated.
Last update: 2020-02-06 04:48:09 UTC
README
Simple, strong encryption.
Installation and documentation
- Available as Composer package eloquent/lockbox.
- API documentation available.
What is Lockbox?
Lockbox is the simplest possible way to implement strong encryption for use in applications. Lockbox uses a combination of well-established technologies to ensure the safety of data. For more information, see the Lockbox website.
Usage
Generating and writing keys
use Eloquent\Lockbox\Key\Generator\KeyGenerator; use Eloquent\Lockbox\Key\Persistence\KeyWriter; $keyGenerator = new KeyGenerator; $key = $keyGenerator->generateKey(); $keyPath = '/path/to/lockbox.key'; $keyWriter = new KeyWriter; $keyWriter->writeFile($key, $keyPath);
Currently there is no way to generate lockbox keys via the command line, but this feature is planned.
Encrypting data
use Eloquent\Lockbox\Encrypter; use Eloquent\Lockbox\Key\Persistence\KeyReader; $keyPath = '/path/to/lockbox.key'; $keyReader = new KeyReader; $key = $keyReader->readFile($keyPath); $encrypter = new Encrypter; echo $encrypter->encrypt($key, 'Super secret data.');
Encrypting multiple data packets with the same key
Lockbox includes 'bound' encrypters that are locked to a particular key, which are convenient for encrypting multiple data packets.
use Eloquent\Lockbox\Bound\BoundEncrypter; use Eloquent\Lockbox\Key\Persistence\KeyReader; $keyPath = '/path/to/lockbox.key'; $keyReader = new KeyReader; $key = $keyReader->readFile($keyPath); $encrypter = new BoundEncrypter($key); echo $encrypter->encrypt('Super secret data.'); echo $encrypter->encrypt('Extra secret data.'); echo $encrypter->encrypt('Mega secret data.');
Decrypting data
use Eloquent\Lockbox\Decrypter; use Eloquent\Lockbox\Key\Persistence\KeyReader; $keyPath = '/path/to/lockbox.key'; $keyReader = new KeyReader; $key = $keyReader->readFile($keyPath); $decrypter = new Decrypter; $encrypted = 'AQF_VjJS9sAL75uuUP_HTu9Do_3itIDaHLLXmh_JLOBRqQeZ_hnDwht4WtEkz3io' . 'iW0WIHb3lANyKqpShyiPcVdj_DbfYiIPEWab8e3vqwEUvoqFFNo'; $result = $decrypter->decrypt($key, $encrypted); if ($result->isSuccessful()) { echo $result->data(); } else { echo 'Decryption failed.'; }
Decrypting multiple data packets with the same key
Lockbox includes 'bound' decrypters that are locked to a particular key, which are convenient for decrypting multiple data packets.
use Eloquent\Lockbox\Bound\BoundDecrypter; use Eloquent\Lockbox\Key\Persistence\KeyReader; $keyPath = '/path/to/lockbox.key'; $keyReader = new KeyReader; $key = $keyReader->readFile($keyPath); $decrypter = new BoundDecrypter($key); $encrypted = array( 'AQF_VjJS9sAL75uuUP_HTu9Do_3itIDaHLLXmh_JLOBRqQeZ_hnDwht4WtEkz3io' . 'iW0WIHb3lANyKqpShyiPcVdj_DbfYiIPEWab8e3vqwEUvoqFFNo', 'AQH44yTs7va1cDoBpX0xVLqIRow5fs8Jj5-DYDJ1R3YY9udBCexmvDs9BH1qJDjC' . 'RSqcGriKi_UkL5per1WHwdxWuPq8QsYiBqeC9e9zypl0Xi1QT3s', 'AQGg0MsYtH0Rboyqssivssupb_GKlBotCpdFtc6WpnMaji8_ZvmGUTRu2DKkxFhA' . 'dk_s0FWZ7NYFjSDt1puIrr7MlB7owNuR5KhUIj04Can0zDCYjJY', ); foreach ($encrypted as $string) { $result = $decrypter->decrypt($string); if ($result->isSuccessful()) { echo $result->data(); } else { echo 'Decryption failed.'; } }