Download the PHP package maymeow/cryptography without Composer
On this page you can find all versions of the php package maymeow/cryptography. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package cryptography
MayMeow/Cryptography
Cryptographic library for encrypting and decrypting data the symetrical and asymetrical way.
This package replaces https://github.com/MayMeow/php-encrypt
Requirements
- PHP 8.*
- openssl extension
What it is contained
- [x] AES Crypto service provider (encrypt, decrypt strings)
- [x] RSA Crypto service provider
- [x] Key derivation
Development
This project contains dev container. To start development build container
This container running as user vscode
with uid 1000
. Start container
or it can be used as configuration for remote PHP processor in PHPStorm.
Usage
Symmetrical encryption
Using one key for encrypt and decrypt data. This library has default method set to aes-256-gcm
Encrypt text as follows
And then you can decrypt text as example shows bellow
Keep your key safe because you need it to decrypt data. You don't need to remember IV (initialization vector) because it is generated for each encryption, and then it is part of encrypted data.
Asymmetrical encryption
Asymmetrical encryption using two different keys. One for encryption and one for decryption. They are mostly known as private and public keys. The public one is that you want to share to someone. With public key you can encrypt data (or someone who want to send you message) and with private key you can decrypt and read data. Private key can be protected by password. Here is example
Exporting and importing keys
To use keys for later in case of encrypt/decrypt data is important to store them on some place. For this I created Readers and Writers. To export keys use Writer as example shows bellow:
If you want implement own Writers they must implement MayMeow\Cryptography\Tools\RsaParametersWriterInterface
.
Importing keys can be done as on example below:
Like on writers you can implement your own Readers too. If you do so your new reader have to implement
MayMeow\Cryptography\Tools\RsaParametersReaderInterface
Locators
Both reader and writer in above example is using Locator. Locators are classes which can return string representation of location where are stored RSAParameters parts. This can be database table, model, table field, path in filesystem and more. Interfaces for Reader and Writer not required to use one, but I recommend it.
If you want implement your own locator, this has to implement MayMeow\Cryptography\Tools\RSAParametersLocatorInterface
.
As example, you can check Tools in test folder.
Cryptographic key derivation
Contribute
Feel free to contribute to this project. For contribution guide please check https://github.com/MayMeow/contribution
License MIT
All versions of cryptography with dependencies
ext-openssl Version *