I want to store passwords in a database in a way I can reuse them to authenticate users (symmetrical encryption).
I read some good information here: https://cheatsheetseries.owasp.org/cheatsheets/Cryptographic_Storage_Cheat_Sheet.html#cryptographic-storage-cheat-sheet
After reading, here is what I (think I) need:
- Symmetrical encryption (not hashing),
- Store my encryption key in my application securely (will be another subject),
- Use salt,
- Use encryption versioning and key rotation,
- No need to guarantee integrity and authenticity of the data: if my password is corrupted and wrong, that's fine for my use case,
- The encrypted data should not be the same length as the password (if it's 8 character-long, the potential attacker should not know),
- The logic should be in my code (do not depend on the database encryption features)
I found that AES encryption should work for my use case, but I'm not sure about the cipher method. Apparently, CTR provides the same data length before and after encryption. CBC doesn't, but it's said to add complexity to the code. Is AES fine for my use case? If yes, what cipher method should I use (CBC, CTR, GCM, CCM...)?
Edit 2022-10-03: I do need to retrieve the clear information. To give more context: I store one public/private key file per user and each file is password-protected. Once the user is logged in to my service, my service does the authentication itself to other services so the user doesn't have to manage his private key.
Edit 2022-10-04: Several users may share the same PKCS#12 which is actually used to authenticate a group. Users are not necessarily aware of the PKCS#12 password.