在已经存储了哈希值的情况下,使用密码中的第二个哈希值加密个人数据



数据库是这样的:

class Users(UserMixin,db.Model):
__tablename__ = "users"
id = db.Column("id", db.Integer, primary_key=True)
username = db.Column(db.String(100))
hash_password = db.Column(db.Text)
secret_content = db.Column(db.Text)

机密内容是高度机密的,我甚至不希望管理员知道数据的内容。我的想法是这样编码内容:

class Users(UserMixin,db.Model):
__tablename__ = "users"
id = db.Column("id", db.Integer, primary_key=True)
username = db.Column(db.String(100))
hash_password = db.Column(db.Text)
secret_content = db.Column(db.Text)
def __init__(self, username , password_hash, secret_content, key):
cipher_suite = Fernet(key)
self.username = username 
self.secret_content = cipher_suite.encrypt(bytes(secret_content))
self.hash_password = password_hash

用于加密数据的密钥对于每个用户应该是不同的。我想通过用sha256散列密码来创建密钥。但是,哈希已经存储在用户中用于登录。因此我会使用另一种哈希算法,例如MD5。

我认为这样做的问题是,如果黑客能够找到/解密这个哈希值,那么他也可以提取真正的密码,因为在这一点上,当黑客暴力破解密码时,你可以消除很多可能性。

我有其他选择吗?还是我需要要求用户提供第二个不相关的密码?

基于@Artjom B.的评论

向钥匙中加入盐。使用PBKDF2加密密钥以对个人数据进行编码。用sh256加密用户登录的密钥

最新更新