Recommend this page to a friend! |
Download .zip |
Info | Documentation | View files (194) | Download .zip | Reputation | Support forum | Blog (1) | Links |
Ratings | Unique User Downloads | Download Rankings | ||||
Not enough user ratings | Total: 333 | All time: 7,102 This week: 381 |
Version | License | PHP version | Categories | |||
phpsimple-encryption 1.0.7 | The PHP License | 7.2 | Cryptography, PHP 7 |
Description | Author | |
This package can be used to encrypt and decrypt data. Recommendations Read encrypted data |
A PHP library that makes encryption and decryption of text easy.
Simply add a dependency on stymiee/php-simple-encryption
to your project's composer.json
file if you
use Composer to manage the dependencies of your project.
Here is a minimal example of a composer.json
file that just defines a dependency on PHP Simple Encryption:
{
"require": {
"stymiee/php-simple-encryption": "^1"
}
}
To get a more detailed introduction to this library, visit the PHP Simple Encryption tutorial on my blog.
require('./vendor/autoload.php');
use Encryption\Encryption;
use Encryption\Exception\EncryptionException;
$text = 'The quick brown fox jumps over the lazy dog';
$key = 'secretkey';
try {
$encryption = Encryption::getEncryptionObject();
$iv = $encryption->generateIv();
$encryptedText = $encryption->encrypt($text, $key, $iv);
$decryptedText = $encryption->decrypt($encryptedText, $key, $iv);
printf('Cipher : %s%s', $encryption->getName(), PHP_EOL);
printf('Encrypted: %s%s', $encryptedText, PHP_EOL);
printf('Decrypted: %s%s', $decryptedText, PHP_EOL);
printf('Version : %s%s', Encryption::VERSION, PHP_EOL);
}
catch (EncryptionException $e) {
echo $e;
}
Outputs
Cipher : AES-256-CBC
Encrypted: lierDqV4Qo3Cm87YU01K+YnQsDGrFsYypjHJVZaagqfLFg7xb2T7b9qfqb4NcoIGcTzqvQbOx72AVgbuRFxqgg==
Decrypted: The quick brown fox jumps over the lazy dog
Version : 1
An exception may be thrown if:
- An invalid/unsupported cipher is attempted to be used (Encryption\Exception\InvalidCipherException
)
- A cipher available in openssl but yet implemented is attempted to be used (Encryption\Exception\CipherNotImplementedException
)
- generateIv()
is unable to generate a initialization vector (Encryption\Exception\GenerateIvException
).
- Encryption::encrypt()
is unable to encrypt the data (Encryption\Exception\EncryptException
).
- Encryption::decrypt()
is unable to decrypt the data (Encryption\Exception\DecryptException
).
The PHP Simple Encryption library currently defaults to AES-256-CBC
. This may change in future versions and will
result in a major version bump when this occurs. You can check the version of your library by calling
Encryption::VERSION
. This library is currently on version "1".
To determine what cipher you are using you can call the getName()
method on your encryption object.
$encryption = Encryption::getEncryptionObject();
$cipherName = $encryption->getName(); // AES-256-CBC
To get a list of ciphers supported by your system and this library you can call Encryption::listAvailableCiphers()
to receive an array of available ciphers. This list is an intersection of available ciphers from your system's
installed version of Openssl and ciphers supported by this library.
Total ciphers supported: 139 Default cipher: AES-256-CBC (version 1)
| AES | Aria/Blowfish | Camellia/Cast5/SM4 | DES/Idea/RC2/RC4/Seed | |-------------------------|---------------|--------------------|-----------------------| | aes-128-cbc | aria-128-cbc | camellia-128-cbc | des-cbc | | aes-128-cbc-hmac-sha1 | aria-128-ccm | camellia-128-cfb | des-cfb | | aes-128-cbc-hmac-sha256 | aria-128-cfb | camellia-128-cfb | des-cfb1 | | aes-128-ccm | aria-128-cfb1 | camellia-128-cfb | des-cfb8 | | aes-128-cfb | aria-128-cfb8 | camellia-128-ctr | des-ecb | | aes-128-cfb1 | aria-128-ctr | camellia-128-ecb | des-ede | | aes-128-cfb8 | aria-128-ecb | camellia-128-ofb | des-ede3 | | aes-128-ctr | aria-128-gcm | camellia-192-cbc | des-ede-cbc | | aes-128-ecb | aria-128-ofb | camellia-192-cfb | des-ede-cfb | | aes-128-gcm | aria-192-cbc | camellia-192-cfb | des-ede-ofb | | aes-128-ofb | aria-192-ccm | camellia-192-cfb | des-ede3-cbc | | aes-128-xts | aria-192-cfb | camellia-192-ctr | des-ede3-cfb | | aes-192-cbc | aria-192-cfb1 | camellia-192-ecb | des-ede3-cfb1 | | aes-192-ccm | aria-192-cfb8 | camellia-192-ofb | des-ede3-cfb8 | | aes-192-cfb | aria-192-ctr | camellia-256-cbc | des-ede3-ofb | | aes-192-cfb1 | aria-192-ecb | camellia-256-cfb | des-ofb | | aes-192-cfb8 | aria-192-gcm | camellia-256-cfb | desx-cbc | | aes-192-ctr | aria-192-ofb | camellia-256-cfb | id-aes128-ccm | | aes-192-ecb | aria-256-cbc | camellia-256-ctr | id-aes128-gcm | | aes-192-gcm | aria-256-ccm | camellia-256-ecb | id-aes192-ccm | | aes-192-ofb | aria-256-cfb | camellia-256-ofb | id-aes192-gcm | | aes-256-cbc | aria-256-cfb1 | cast5-cbc | id-aes256-ccm | | aes-256-cbc-hmac-sha1 | aria-256-cfb8 | cast5-cfb | id-aes256-gcm | | aes-256-cbc-hmac-sha256 | aria-256-ctr | cast5-ecb | idea-cbc | | aes-256-ccm | aria-256-ecb | cast5-ofb | idea-cfb | | aes-256-cfb | aria-256-gcm | chacha20 | idea-ecb | | aes-256-cfb1 | aria-256-ofb | chacha20-poly1305 | idea-ofb | | aes-256-cfb8 | bf-cbc | seed-cbc | rc2-40-cbc | | aes-256-ctr | bf-cfb | seed-cfb | rc2-64-cbc | | aes-256-ecb | bf-ecb | seed-ecb | rc2-cbc | | aes-256-gcm | bf-ofb | seed-ofb | rc2-cfb | | aes-256-ofb | sm4-cbc | | rc2-ecb | | aes-256-xts | sm4-cfb | | rc2-ofb | | | sm4-ctr | | rc4 | | | sm4-ecb | | rc4-40 | | | | | rc4-hmac-md5 |
If the text to be encrypted contains trailing null characters they will be removed when decrypting those values.
Some ciphers may not work on your version of PHP. The newer your version of PHP (and its openssl extension), the more ciphers that will be available to you.
If you require assistance using this library start by viewing the HELP.md file included in this package. It includes common problems and their solutions.
If you need additional assistance, I can be found at Stack Overflow. Be sure when you ask a question pertaining to the usage of this library be sure to tag your question with the PHP and encryption tags. Make sure you follow their guide for asking a good question as poorly asked questions will be closed, and I will not be able to assist you.
A good question will include all the following: - A description of the problem (what are you trying to do? what results are you expecting? what results are you actually getting?) - The code you are using (only post the relevant code) - Your unencrypted text - The key you are using - The IV you are using - The output of your method call(s) - Any error message(s) you are getting
Do not use Stack Overflow to report bugs. Bugs may be reported here.
Files |
File | Role | Description | ||
---|---|---|---|---|
.github (1 directory) | ||||
artifacts (1 file) | ||||
src (1 directory) | ||||
tests (2 directories) | ||||
.editorconfig | Data | Auxiliary data | ||
CHANGELOG | Data | Auxiliary data | ||
composer.json | Data | Auxiliary data | ||
CONTRIBUTING.md | Data | Auxiliary data | ||
HELP.md | Data | Auxiliary data | ||
license.txt | Doc. | Documentation | ||
phpunit.xml | Data | Auxiliary data | ||
README.md | Doc. | Documentation | ||
SECURITY.md | Data | Auxiliary data |
Files | / | src | / | Encryption |
File | Role | Description | ||
---|---|---|---|---|
Cipher (4 files, 14 directories) | ||||
Exceptions (7 files) | ||||
Interfaces (5 files) | ||||
Traits (8 files) | ||||
Encryption.php | Class | Class source |
Files | / | src | / | Encryption | / | Cipher |
File | Role | Description | ||
---|---|---|---|---|
AES (36 files) | ||||
ARIA (27 files) | ||||
BF (4 files) | ||||
CAMELLIA (21 files) | ||||
CAST5 (4 files) | ||||
CHACHA20 (2 files) | ||||
DES (16 files) | ||||
DESX (1 file) | ||||
ID (13 files) | ||||
IDEA (4 files) | ||||
RC2 (6 files) | ||||
RC4 (3 files) | ||||
SEED (4 files) | ||||
SM4 (5 files) | ||||
ACipher.php | Class | Class source | ||
ACipherAeadMode.php | Class | Class source | ||
ACipherNoInitializationVector.php | Class | Class source | ||
ACipherWithInitializationVector.php | Class | Class source |
Files | / | src | / | Encryption | / | Cipher | / | AES |
File | Role | Description |
---|---|---|
Aes128cbc.php | Class | Class source |
Aes128cbchmacsha1.php | Class | Class source |
Aes128cbchmacsha256.php | Class | Class source |
Aes128ccm.php | Class | Class source |
Aes128cfb.php | Class | Class source |
Aes128cfb1.php | Class | Class source |
Aes128cfb8.php | Class | Class source |
Aes128ctr.php | Class | Class source |
Aes128ecb.php | Class | Class source |
Aes128gcm.php | Class | Class source |
Aes128ocb.php | Class | Class source |
Aes128ofb.php | Class | Class source |
Aes128xts.php | Class | Class source |
Aes192cbc.php | Class | Class source |
Aes192ccm.php | Class | Class source |
Aes192cfb.php | Class | Class source |
Aes192cfb1.php | Class | Class source |
Aes192cfb8.php | Class | Class source |
Aes192ctr.php | Class | Class source |
Aes192ecb.php | Class | Class source |
Aes192gcm.php | Class | Class source |
Aes192ocb.php | Class | Class source |
Aes192ofb.php | Class | Class source |
Aes256cbc.php | Class | Class source |
Aes256cbchmacsha1.php | Class | Class source |
Aes256cbchmacsha256.php | Class | Class source |
Aes256ccm.php | Class | Class source |
Aes256cfb.php | Class | Class source |
Aes256cfb1.php | Class | Class source |
Aes256cfb8.php | Class | Class source |
Aes256ctr.php | Class | Class source |
Aes256ecb.php | Class | Class source |
Aes256gcm.php | Class | Class source |
Aes256ocb.php | Class | Class source |
Aes256ofb.php | Class | Class source |
Aes256xts.php | Class | Class source |
Files | / | src | / | Encryption | / | Cipher | / | ARIA |
File | Role | Description |
---|---|---|
Aria128cbc.php | Class | Class source |
Aria128ccm.php | Class | Class source |
Aria128cfb.php | Class | Class source |
Aria128cfb1.php | Class | Class source |
Aria128cfb8.php | Class | Class source |
Aria128ctr.php | Class | Class source |
Aria128ecb.php | Class | Class source |
Aria128gcm.php | Class | Class source |
Aria128ofb.php | Class | Class source |
Aria192cbc.php | Class | Class source |
Aria192ccm.php | Class | Class source |
Aria192cfb.php | Class | Class source |
Aria192cfb1.php | Class | Class source |
Aria192cfb8.php | Class | Class source |
Aria192ctr.php | Class | Class source |
Aria192ecb.php | Class | Class source |
Aria192gcm.php | Class | Class source |
Aria192ofb.php | Class | Class source |
Aria256cbc.php | Class | Class source |
Aria256ccm.php | Class | Class source |
Aria256cfb.php | Class | Class source |
Aria256cfb1.php | Class | Class source |
Aria256cfb8.php | Class | Class source |
Aria256ctr.php | Class | Class source |
Aria256ecb.php | Class | Class source |
Aria256gcm.php | Class | Class source |
Aria256ofb.php | Class | Class source |
Files | / | src | / | Encryption | / | Cipher | / | BF |
Files | / | src | / | Encryption | / | Cipher | / | CAMELLIA |
File | Role | Description |
---|---|---|
Camellia128cbc.php | Class | Class source |
Camellia128cfb.php | Class | Class source |
Camellia128cfb1.php | Class | Class source |
Camellia128cfb8.php | Class | Class source |
Camellia128ctr.php | Class | Class source |
Camellia128ecb.php | Class | Class source |
Camellia128ofb.php | Class | Class source |
Camellia192cbc.php | Class | Class source |
Camellia192cfb.php | Class | Class source |
Camellia192cfb1.php | Class | Class source |
Camellia192cfb8.php | Class | Class source |
Camellia192ctr.php | Class | Class source |
Camellia192ecb.php | Class | Class source |
Camellia192ofb.php | Class | Class source |
Camellia256cbc.php | Class | Class source |
Camellia256cfb.php | Class | Class source |
Camellia256cfb1.php | Class | Class source |
Camellia256cfb8.php | Class | Class source |
Camellia256ctr.php | Class | Class source |
Camellia256ecb.php | Class | Class source |
Camellia256ofb.php | Class | Class source |
Files | / | src | / | Encryption | / | Cipher | / | CAST5 |
File | Role | Description |
---|---|---|
Cast5cbc.php | Class | Class source |
Cast5cfb.php | Class | Class source |
Cast5ecb.php | Class | Class source |
Cast5ofb.php | Class | Class source |
Files | / | src | / | Encryption | / | Cipher | / | CHACHA20 |
File | Role | Description |
---|---|---|
Chacha20.php | Class | Class source |
Chacha20poly1305.php | Class | Class source |
Files | / | src | / | Encryption | / | Cipher | / | DES |
File | Role | Description |
---|---|---|
Descbc.php | Class | Class source |
Descfb.php | Class | Class source |
Descfb1.php | Class | Class source |
Descfb8.php | Class | Class source |
Desecb.php | Class | Class source |
Desede.php | Class | Class source |
Desede3.php | Class | Class source |
Desede3cbc.php | Class | Class source |
Desede3cfb.php | Class | Class source |
Desede3cfb1.php | Class | Class source |
Desede3cfb8.php | Class | Class source |
Desede3ofb.php | Class | Class source |
Desedecbc.php | Class | Class source |
Desedecfb.php | Class | Class source |
Desedeofb.php | Class | Class source |
Desofb.php | Class | Class source |
Files | / | src | / | Encryption | / | Cipher | / | ID |
File | Role | Description |
---|---|---|
Idaes128ccm.php | Class | Class source |
Idaes128gcm.php | Class | Class source |
Idaes128wrap.php.txt | Doc. | Documentation |
Idaes128wrappad.php.txt | Doc. | Documentation |
Idaes192ccm.php | Class | Class source |
Idaes192gcm.php | Class | Class source |
Idaes192wrap.php.txt | Doc. | Documentation |
Idaes192wrappad.php.txt | Doc. | Documentation |
Idaes256ccm.php | Class | Class source |
Idaes256gcm.php | Class | Class source |
Idaes256wrap.php.txt | Doc. | Documentation |
Idaes256wrappad.php.txt | Doc. | Documentation |
Idsmimealgcms3deswrap.php.txt | Doc. | Documentation |
Files | / | src | / | Encryption | / | Cipher | / | IDEA |
File | Role | Description |
---|---|---|
Ideacbc.php | Class | Class source |
Ideacfb.php | Class | Class source |
Ideaecb.php | Class | Class source |
Ideaofb.php | Class | Class source |
Files | / | src | / | Encryption | / | Cipher | / | RC2 |
File | Role | Description |
---|---|---|
Rc240cbc.php | Class | Class source |
Rc264cbc.php | Class | Class source |
Rc2cbc.php | Class | Class source |
Rc2cfb.php | Class | Class source |
Rc2ecb.php | Class | Class source |
Rc2ofb.php | Class | Class source |
Files | / | src | / | Encryption | / | Cipher | / | RC4 |
File | Role | Description |
---|---|---|
Rc4.php | Class | Class source |
Rc440.php | Class | Class source |
Rc4hmacmd5.php | Class | Class source |
Files | / | src | / | Encryption | / | Cipher | / | SEED |
File | Role | Description |
---|---|---|
Seedcbc.php | Class | Class source |
Seedcfb.php | Class | Class source |
Seedecb.php | Class | Class source |
Seedofb.php | Class | Class source |
Files | / | src | / | Encryption | / | Cipher | / | SM4 |
File | Role | Description |
---|---|---|
Sm4cbc.php | Class | Class source |
Sm4cfb.php | Class | Class source |
Sm4ctr.php | Class | Class source |
Sm4ecb.php | Class | Class source |
Sm4ofb.php | Class | Class source |
Files | / | src | / | Encryption | / | Exceptions |
File | Role | Description |
---|---|---|
CipherNotImplementedException.php | Class | Class source |
DecryptException.php | Class | Class source |
EncryptException.php | Class | Class source |
EncryptionException.php | Class | Class source |
GenerateIvException.php | Class | Class source |
InvalidCipherException.php | Class | Class source |
InvalidVersionException.php | Class | Class source |
Files | / | src | / | Encryption | / | Interfaces |
File | Role | Description |
---|---|---|
ICipher.php | Class | Class source |
IEncryptAeadMode.php | Class | Class source |
IEncryptWithInitializationVector.php | Class | Class source |
IEncryptWithoutInitializationVector.php | Class | Class source |
IGenerateInitializationVector.php | Class | Class source |
Files | / | src | / | Encryption | / | Traits |
File | Role | Description |
---|---|---|
Decrypt.php | Class | Class source |
DecryptAeadMode.php | Class | Class source |
DecryptNoIV.php | Class | Class source |
encryptWithoutPadding.php.txt | Doc. | Documentation |
EncryptWithPadding.php | Class | Class source |
EncryptWithPaddingAeadMode.php | Class | Class source |
EncryptWithPaddingNoIV.php | Class | Class source |
GenerateIv.php | Class | Class source |
Files | / | tests | / | functional |
File | Role | Description |
---|---|---|
PaddingWithIvAeadTest.php | Class | Class source |
PaddingWithIvTest.php | Class | Class source |
PaddingWithoutIvTest.php | Class | Class source |
Files | / | tests | / | unit |
File | Role | Description | ||
---|---|---|---|---|
ciphers (1 file) | ||||
traits (7 files) | ||||
EncryptionTest.php | Class | Class source |
Files | / | tests | / | unit | / | traits |
File | Role | Description |
---|---|---|
DecryptAeadModeTest.php | Class | Class source |
DecryptNoIvTest.php | Class | Class source |
DecryptTest.php | Class | Class source |
EncryptWithPaddingAeadModeTest.php | Class | Class source |
EncryptWithPaddingNoIVTest.php | Class | Class source |
EncryptWithPaddingTest.php | Class | Class source |
GenerateIvTest.php | Class | Class source |
phpsimple-encryption-2021-08-30.zip 129KB | |
phpsimple-encryption-2021-08-30.tar.gz 56KB | |
Install with Composer |
Version Control | Unique User Downloads | Download Rankings | |||||||||||||||
100% |
|
|
Applications that use this package |
If you know an application of this package, send a message to the author to add a link here.