Importance of the key size in the Rfc2898DeriveBytes (PBKDF2) implementation

杀马特。学长 韩版系。学妹 提交于 2019-12-05 03:16:24

Generally you use PKCS#5 v2 / RFC2898 to create a symmetric key from a user password. The size is important because it must match the required size of the symmetric algorithm you'll be using.

aes.Key = deriveBytes.GetBytes (16); // 16 * 8 = 128 bits

However you seems to be looking at keeping an hash of passwords, not for a key, so the size is not as important in your specific case. You can safely fix it to the hash size (20 bytes for SHA1) if you want a specific value.

General note (for people where performance matters): using PKCS#5 v2 (or older) will take a lot longer (iteration count) than using a salted hash or an HMAC.

osgx

keysize is the size of desired key; So if you want to get a big derived key, use bigger keySize.

The time needed for bigger keysize is proportional to int(keysize/hashsize), so you should set keysize to at least the same length as hashsize.

Also, you should use derived keys of recommended length, when they are used in some cypher, e.g. AES (128 - 256 bit).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!