我正在查看这段代码并遇到了这些评论,这些评论说没有盐的加密是不安全的。当您已经为每个值使用随机 IV 时,为什么会不安全?我认为评论可能不正确,但它是一个受欢迎的宝石,所以我不确定。我认为它key真的被视为一个password,我只是想验证一下。
https://github.com/attr-encrypted/encryptor/blob/master/lib/encryptor.rb#L57
if options[:iv]
cipher.iv = options[:iv]
if options[:salt].nil?
# Use a non-salted cipher.
# This behaviour is retained for backwards compatibility. This mode
# is not secure and new deployments should use the :salt options
# wherever possible.
cipher.key = options[:key]
else
# Use an explicit salt (which can be persisted into a database on a
# per-column basis, for example). This is the preferred (and more
# secure) mode of operation.
cipher.key = OpenSSL::PKCS5.pbkdf2_hmac_sha1(options[:key], options[:salt], 2000, cipher.key_len)
end
else
cipher.pkcs5_keyivgen(options[:key])
end
我打算从头开始写一些东西,并且只使用基础库。我的密钥来自SecureRandom.base64(32),我将其存储在代码中,然后 Base64 对其进行解码以获得二进制密钥,并将其用于加密/解密,以及每个数据元素的随机 IV。我认为我不需要为此加盐。想确认。