Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bayfrontmedia/encryptor
A fast, simple two-way encryption library utilizing OpenSSL.
https://github.com/bayfrontmedia/encryptor
decrypt decryption encrypt encryption encryptor openssl php
Last synced: about 6 hours ago
JSON representation
A fast, simple two-way encryption library utilizing OpenSSL.
- Host: GitHub
- URL: https://github.com/bayfrontmedia/encryptor
- Owner: bayfrontmedia
- License: mit
- Created: 2020-08-28T15:41:16.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2023-01-26T18:20:22.000Z (almost 2 years ago)
- Last Synced: 2024-09-18T01:35:48.899Z (about 2 months ago)
- Topics: decrypt, decryption, encrypt, encryption, encryptor, openssl, php
- Language: PHP
- Homepage:
- Size: 15.6 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
- Security: .github/SECURITY.md
Awesome Lists containing this project
README
## Encryptor
A fast, simple two-way encryption library utilizing OpenSSL.
- [License](#license)
- [Author](#author)
- [Requirements](#requirements)
- [Installation](#installation)
- [Usage](#usage)## License
This project is open source and available under the [MIT License](LICENSE).
## Author
- [Bayfront Media homepage](https://www.bayfrontmedia.com?utm_source=github&utm_medium=direct)
- [Bayfront Media GitHub](https://github.com/bayfrontmedia)## Requirements
* PHP `^8.0`
* OpenSSL PHP extension
* JSON PHP extension## Installation
```
composer require bayfrontmedia/encryptor
```## Usage
### Start using Encryptor
A private, reproducible key must be passed to the constructor.
The same key must be used when encrypting and decrypting.
If the key used to encrypt a value is lost, it will not be able to be decrypted.An optional second constructor parameter allows you to specify which [cipher method](https://www.php.net/manual/en/function.openssl-get-cipher-methods.php) to use.
By default, Encryptor uses `AES-256-CBC`.If an invalid cipher method is used, a `Bayfront\Encryptor\InvalidCipherException` exception will be thrown.
```
use Bayfront\Encryptor\Encryptor;$encryptor = new Encryptor('private_key');
```### Public methods
- [getKey](#getkey)
- [getCipher](#getcipher)
- [encrypt](#encrypt)
- [encryptString](#encryptstring)
- [decrypt](#decrypt)
- [decryptString](#decryptstring)
### getKey
**Description:**
Returns the encryption key.
**Parameters:**
- None
**Returns:**
- (string)
### getCipher
**Description:**
Returns the cipher method used for encryption.
**Parameters:**
- None
**Returns:**
- (string)
### encrypt
**Description:**
Encrypts a given value.
**Parameters:**
- `$value` (mixed)
- `$serialize = true` (bool)**Returns:**
- (string)
**Throws:**
- `Bayfront\Encryptor\EncryptException`
**Example:**
```
try {$encrypted = $encryptor->encrypt([
'name' => 'John',
'user_id' => 8
]);} catch (EncryptException $e) {
die($e->getMessage());
}
```
### encryptString
**Description:**
Encrypts a string without serialization.
**Parameters:**
- `$value` (string)
**Returns:**
- (string)
**Throws:**
- `Bayfront\Encryptor\EncryptException`
**Example:**
```
try {$encrypted_string = $encryptor->encryptString('A string to encrypt');
} catch (EncryptException $e) {
die($e->getMessage());
}
```
### decrypt
**Description:**
Decrypts a given value.
**Parameters:**
- `$data` (string)
- `$unserialize = true` (bool)**Returns:**
- (mixed)
**Throws:**
- `Bayfront\Encryptor\DecryptException`
**Example:**
```
try {$decrypted = $encryptor->decrypt($encrypted);
} catch (DecryptException $e) {
die($e->getMessage());
}
```
### decryptString
**Description:**
Decrypts a string without unserialization.
**Parameters:**
- `$data` (string)
**Returns:**
- (string)
**Throws:**
- `Bayfront\Encryptor\DecryptException`
**Example:**
```
try {$decrypted_string = $encryptor->decryptString($encrypted_string);
} catch (DecryptException $e) {
die($e->getMessage());
}
```