两个加密/散列情况,哪一个最好

时间:2014-03-02 10:22:38

标签: cryptography aes pbkdf2

考虑以下两种情况,哪一种最好,最安全一种

第一个案例

//key1 generated from static salt and user password, because in case attacker don't know about source code (bad assumption, but still my assumption), attacker have only hashed or encrypted data + random generated salt
staticSalt = "StaticSalt"
key1 = pbkdf2(userPassword, staticSalt, iteration)

//key2 generated from key1 and randomSalt, this will be actual key to be used for encryption
randomSalt = GenerateRandomSalt()
key2 = pbkdf2(key1, randomSalt, iteration)

aes.Key = Key2
aes.IV = aes.GenerateIV()

第二案

//directly generate key from randomSalt and password
randomSalt = GenerateRandomSalt()
key1 = pbkdf2(userPassword, randomSalt, iteration)

aes.Key = Key1
aes.IV = aes.GenerateIV()

我的问题是,使用第一种情况有任何缺点,它会增加或减少熵,还是使安全性降低?

或第二种情况是更好更安全的做法

寻找一些加密专家的答案。

1 个答案:

答案 0 :(得分:0)

这个问题更适合Sec.SE

如果您使用此代码存储密码,请参阅this question,特别是有关如何正确散列和存储密码的信息。


第一种情况似乎增加了默默无闻,而不是安全。从长远来看,这实际上可能会通过增加攻击区域来降低安全性(即更多的地方可以发生错误)。

请记住,don't want to be a Dave

相关问题