I was wondering whether this encryption / decryption flow is very solid / secure. I encrypt the data using AES CBC 256 bit with an static IV.

When the user logs in with his Firebase account (first phase of authentication), he gets the option to enter a security password. After that is done, some encryption values will be retrieved like the prefix, suffix and IV. I create the key as following: prefix + given key + suffix. After that I decrypt a retrieved string, and if I get a certain text back, I know it is the right key and start decrypting it for this session.

So to sum it up:

  1. Log in with Firebase
  2. Get encryption values like prefix, suffix, IV and encrypted string
  3. Let user enter password
  4. Create an key in the format prefix + given password + suffix and apply an static IV
  5. Use the generated key to decrypt a string
  6. If it is successfully decrypted, use the key for this session

Note: I won't use public / private key exchange due to reasons.


1 Answer 1


I was wondering whether this encryption / decryption flow is very solid / secure.

What you have described is not an encryption scheme*, but a scheme for user authentication, that is a user tries to log-in, provides the password and you want to check if that password belongs to the given user.

Now what you have described will probably achieve that goal, but it's not the kind of approach that is really "considered" good for this use-case in cryptography:

  • The length of passwords is limited by the cipher's keysize (eg 32 bytes?).
  • Ciphers are not designed to provide good security with non-uniformly distributed keys.
  • This approach will require quite low storage and will be very fast to verify meaning an attacker can just ask eg a GPU to run through billions of possible passwords per second.

But on the plus-side, using the password as a key on a fixed message is kind of a hash function and using the IV / the prefix / the suffix kind of is a salt, which are both central ingredients for password hashing.

Now what you actually want here is a password hashing scheme (PHS). That is a function that takes a salt, that you store in your database, a cost parameter (set) and a password and outputs a value deterministic in these parameters that you can check against a pre-stored value in your database. You would then generate a unique salt for each user and use the highest cost parameter in terms of time and memory that you can tolerate to slow down attackers for the case when your database leaks. Common PHSs are Argon2, bcrypt, scrypt or if you're out of options PBKDF2.

*: An encryption scheme would specify, given a key, a nonce and a message how to generate an encrypted message.

  • $\begingroup$ It seems like an both a user authentication and encryption scheme to me, as the user has to log in, after which the encryption progress will start. I need to decrypt a lot of strings, therefore the mentioned "PBKDF2", which I used before, is way too slow. I will look into PHS, but I need to be able to decrypt 50K strings within half a second (preferably less), so that is most of the times the problem. $\endgroup$
    – Mark D
    Jul 8, 2018 at 10:14
  • $\begingroup$ @MarkD then don't run a PHS for every file, but just run it once for each user to recover a (high-entropy) symmetric key and use that symmetric key to decrypt the various files? $\endgroup$
    – SEJPM
    Jul 8, 2018 at 10:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.