defuse/php-encryption
Secure, hard-to-misuse PHP encryption library for encrypting data with keys or passwords. Requires PHP 5.6+ and OpenSSL 1.0.1+. Simple API inspired by libsodium, built to avoid common crypto mistakes.
Here is a high-level description of how this library works. Any discrepancy between this documentation and the actual implementation will be considered a security bug.
Let's start with the following definitions:
"\xDE\xF5\x02\x00"."DefusePHP|V2|KeyForAuthentication"."DefusePHP|V2|KeyForEncryption".To encrypt a message m using a 32-byte key k, the following steps are taken:
Decryption is roughly the reverse process (see the code for details, since the security of the decryption routine is highly implementation-dependent).
For encryption using a password p, steps 1-3 above are replaced by:
The remainder of the process is the same. Notice the reuse of the same salt for PBKDF2-SHA256 and HKDF-SHA256. The prehashing of the password in step 2 is done to prevent a DoS attack using long passwords.
For KeyProtectedByPassword, the serialized key is encrypted according to the
password encryption defined above. However, the actual password used for
encryption is the SHA256 hash of the password the user provided. This is done in
order to provide domain separation between the message encryption in the user's
application and the internal key encryption done by this library. It fixes
a key replacement chosen-protocol
attack.
How can I help you explore Laravel packages today?