File encryption with weak password, bcrypt or SHA-256 + AES-256?

I start with a weak password (8 lowercase characters for ex) and a file. I need to encrypt this file using this password. The result should be protected from known attacks.

Approach 1: I can use the password using SHA-256, and then use the resulting hash and file as input for the AES-256, providing me with an encrypted file. I understand that both SHA-256 and AES-256 are very fast. Wouldn't that make the file vulnerable to brute force attack?

For example, is it possible to capture the rainbow table of pre-computed SHA-256 hashes and, assuming that it is a really small file and a really weak password, try AES-256 to decrypt using each hash from this table in a reasonable amount of time (several months with specialized equipment).

Approach 2: Use bcrypt. If I understand correctly, bcrypt is better for encrypting files than SHA-256 + AES-256, since the key generation scheme has a working factor, which leads to a stronger key. Or am I wrong?

The Ruby and Python implementations (wrappers?) I've seen focus on using bcrypt as a hash scheme for passwords, not the cipher itself. Can I use bcrypt for a hash in a weak pass AND encrypt the file in "one step"?

Approach 3: use bcrypt to transfer the hash, use this hash and file as inputs to AES-256, giving me an encrypted file. This will ensure that the "key is too fast to create" a problem. (Assume this is a problem). However, bcrypt hashing is 448 bits, while AES-256 is a 256-bit key. The naive solution is to simply drop the trailing bits of the hash and use it as a key for the AES-256. I would not go along this route because I do not know enough about cryptography to find out what the consequences are.

EDIT: I can't salt the pass, as this is for an offline application. i.e. There is no reasonable place to store salt. I can salt the passage and store the salt unencrypted along with the encrypted file. Salts are almost inherently publicly available / visible if they say that the database is compromised. The purpose of salt is to prevent an attack on the rainbow table. Thanks Nemo, below.

+6
source share
1 answer

Approach 4: Use PKCS # 5 (PBKDF2 to get the key from the pass + cipher of your choice for encryption using this key), preferably someone else.

And do not forget the salt. (You store it with encrypted data. It should be only 8 bytes).

+11
source

Source: https://habr.com/ru/post/889705/


All Articles