https://github.com/codezero-be/encrypter
Encrypt and decrypt data in PHP
https://github.com/codezero-be/encrypter
encrypter laravel php vanilla-php
Last synced: 9 months ago
JSON representation
Encrypt and decrypt data in PHP
- Host: GitHub
- URL: https://github.com/codezero-be/encrypter
- Owner: codezero-be
- License: mit
- Created: 2015-03-27T22:22:36.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2019-09-26T14:19:05.000Z (over 6 years ago)
- Last Synced: 2024-04-25T19:43:02.394Z (over 1 year ago)
- Topics: encrypter, laravel, php, vanilla-php
- Language: PHP
- Size: 21.5 KB
- Stars: 2
- Watchers: 4
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Encrypter
[]()
[]()
[](https://scrutinizer-ci.com/g/codezero-be/encrypter/build-status/master)
[](https://scrutinizer-ci.com/g/codezero-be/encrypter/?branch=master)
[](https://scrutinizer-ci.com/g/codezero-be/encrypter/?branch=master)
[](https://packagist.org/packages/codezero/encrypter)
[](https://ko-fi.com/R6R3UQ8V)
#### Encrypt and decrypt strings in PHP.
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.
## Installation
Install this package through Composer:
```php
composer require codezero/encrypter
```
## Vanilla PHP Implementation
Autoload the vendor classes:
```php
require_once 'vendor/autoload.php'; // Path may vary
```
Choose a key. You will need the same key that was used to encrypt a string, to decrypt it.
```php
$key = 'my secret key';
```
And then use the `DefaultEncrypter` implementation:
```php
$encrypter = new \CodeZero\Encrypter\DefaultEncrypter($key);
```
## Usage
### Encrypt a string
```php
$encrypted = $encrypter->encrypt('some string');
```
### Decrypt an encrypted string
```php
try {
$decrypted = $encrypter->decrypt($encrypted);
} catch (\CodeZero\Encrypter\DecryptException $exception) {
// Decryption failed...
}
```
## Testing
```
$ composer run test
```
## Security
If you discover any security related issues, please [e-mail me](mailto:ivan@codezero.be) instead of using the issue tracker.
## License
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.