-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Encrypting/decrypting very slow due to use of de-/encryptWithPassword() #812
Comments
In principle I can't think of an issue with what you are proposing as long as it is backwards compatible but it would be good to get more information. If you can provide any links that can back up your assertions that would be appreciated. I noted from the php-encryption lib that they note PBKDF2 is slower but I didn't find much in the way of pros and cons between password vs key other than that. Is the use of |
See defuse/php-encryption#359 for information about PBKDF2 being slow vs using a |
Also see defuse/php-encryption#161 which is the original use case for implementing the PBKDF2 algorithm. From what I understand it's for cases where you don't store the key on the server, but have it supplied by the user in the form of a password. PBKDF2 is then used to turn the password into an encryption key and it's meant to be slow to protect against attacks like brute force. However if you are storing the encryption key on the server, and it's a strong encryption key then PBKDF2 is not necessary, only HKDF should be secure enough. The |
Perhaps when this is merged and in a release, the following documentation should be updated too to reflect the ability to use a V5 Security Improvements#6.0.0 Installation#Generating encryption keys From skimming through he documentation I couldn't find other places referencing encryption keys. |
Ok, I found the |
Hi, I just wanted to note that I encountered this exact issue too, when I was implementing the (php-encryption) library directly in my own project for different purposes (after having found it in this project). In my case when decrypting just one item while using After switching to the methods described in the defuse/php-encryption documentation this slowdown essentially disappeared. Checkout the neat bin script the lib provides to generate a key, might want to include that in the docs maybe? The performance hit is significant, I came here to see if it was a known problem. Good to see someone already beat me to it. Would be good to see this updated upstream :) |
Allow CryptTrait to accept a \Defuse\Crypto\Key as encryption key #812
Closing this issue as @SunMar has produced a fix which will be added to the next release |
Hi,
During tests we discovered that encrypting and decrypting is very slow. This is caused by the use of the PBKDF2 algorithm in
KeyOrPassword
(from thedefuse/php-encryption
dependency), which can be traced back toCryptTrait
where theencryptWithPassword()
anddecryptWithPassword()
methods are used. The use of this algorithm is secure if you're unsure about how good your encryption key is, however if you know you have a secure encryption key, then PBKDF2 is not needed.An easy way to get a big performance boost here is by allowing a
Key
object to be used as encryption key instead of a string. If it's aKey
object thenencrypt()
instead ofencryptWithPassword()
anddecrypt()
instead ofdecryptWithPassword()
can be used. With aKey
the encryption library trusts the key and skips PBKDF2 using only the much faster HKDF algorithm.This could be implemented backwards compatible by checking in
CryptTrait
if$this->encryptionKey
is an instance ofKey
or not. I can see to make a pull request for this but would first like to know if something like this would be accepted.The text was updated successfully, but these errors were encountered: