-
Notifications
You must be signed in to change notification settings - Fork 8
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
CryptoService is unsafe by design #44
Comments
On it, let me see... |
Mmm... I don't think this is right. The generateKey method uses the salt AND the secret: In fact, you use that exact line on your example also! So, in order to regenerate the key, you need the secret. You can easily test it. First, encrypt a text with the secret "secret1". Then, change the secret to "secret2". Then, try to decrypt the text. You won't be able. |
It's not using the "secret" attribute, but a variable generated from the salt: private Map<String, byte[]> _encrypt(String text) {
|
I think you are confused by the unfortunate choice of variable names. It is true that the cipher uses a local variable called "secret". In order to avoid misinterpretations, it would be better to rename the local variable of the line that you mention to: Anyway, if you look inside the "generateKey" function, on the line 45 of the file, you can see that the key is generated using the "secret" attribute, not the local variable. Again, it would be less confusing to use "this", so we can change that line to: KeySpec spec = new PBEKeySpec(this.secret.toCharArray(), salt, 20000, 128) I hope it is more clear now. |
CryptoService is not using the "secret" parameter(password) set on init(...) method for ciphering or deciphering. Instead, it's using a salt and a iv parameter that are returned plain ( hex encoded ) at the end of the encrypted text.
Instead of using the provided "secret", the code is generating a SecretKeySpec from the salt.
Salt and IV parameters can be easily obtained:
The secret key can then be easily regenerated:
And then, the text can be decrypted ( without knowin the password set to the CryptoService!! )
The text was updated successfully, but these errors were encountered: