|
| 1 | +# Encrypter |
| 2 | + |
| 3 | +[]() |
| 4 | +[]() |
| 5 | +[](https://travis-ci.org/codezero-be/encrypter) |
| 6 | +[](https://scrutinizer-ci.com/g/codezero-be/encrypter) |
| 7 | +[](https://packagist.org/packages/codezero/encrypter) |
| 8 | + |
| 9 | +#### Encrypt and decrypt strings in PHP. |
| 10 | + |
| 11 | +This package includes an adapter for [Laravel](http://laravel.com/)'s `Encrypter` that adheres to my `Encrypter` interface. This can be used in vanilla PHP. Other implementations might be added in the future. |
| 12 | + |
| 13 | +## Installation |
| 14 | + |
| 15 | +Install this package through Composer: |
| 16 | + |
| 17 | + composer require codezero/encrypter |
| 18 | + |
| 19 | +## Vanilla PHP Implementation |
| 20 | + |
| 21 | +Autoload the vendor classes: |
| 22 | + |
| 23 | + require_once 'vendor/autoload.php'; // Path may vary |
| 24 | + |
| 25 | +Choose a key. You will need the same key that was used to encrypt a string, to decrypt it. |
| 26 | + |
| 27 | + $key = 'my secret key'; |
| 28 | + |
| 29 | +And then use the `DefaultEncrypter` implementation: |
| 30 | + |
| 31 | + $encrypter = new \CodeZero\Encrypter\DefaultEncrypter($key); |
| 32 | + |
| 33 | +## Usage |
| 34 | + |
| 35 | +### Encrypt a string |
| 36 | + |
| 37 | + $encrypted = $encrypter->encrypt('some string'); |
| 38 | + |
| 39 | +### Decrypt an encrypted string |
| 40 | + |
| 41 | + try { |
| 42 | + $decrypted = $encrypter->decrypt($encrypted); |
| 43 | + } catch (\CodeZero\Encrypter\DecryptException $exception) { |
| 44 | + // Decryption failed... |
| 45 | + } |
| 46 | +## Testing |
| 47 | + |
| 48 | + $ vendor/bin/phpspec run |
| 49 | + |
| 50 | +## Security |
| 51 | + |
| 52 | +If you discover any security related issues, please [e-mail me](mailto:ivan@codezero.be) instead of using the issue tracker. |
| 53 | + |
| 54 | +## License |
| 55 | + |
| 56 | +The MIT License (MIT). Please see [License File](LICENSE.md) for more information. |
| 57 | + |
| 58 | +--- |
| 59 | +[](https://github.com/igrigorik/ga-beacon) |
0 commit comments