0
Rfc2898DeriveBytes k1 = new Rfc2898DeriveBytes(pwd1, salt1, myIterations);

Rfc2898DeriveBytes k2 = new Rfc2898DeriveBytes(pwd1, salt1);

// Encrypt the data.
TripleDES encAlg = TripleDES.Create();
encAlg.Key = k1.GetBytes(16);

My question is why is .GetByte 16? Also is it the same for RijndaelManaged? it requires 16 bytes?

4

1 回答 1

1

这是因为算法所需的密钥大小:

当然,没有什么能阻止您从密钥派生器生成更多字节,但这些算法要么修剪不需要的数据,要么在大小不合法时根本无法工作 - http://msdn.microsoft.com/en-us/库/system.security.cryptography.symmetricalgorithm.legalkeysizes(v=vs.110).aspx

于 2014-08-22T18:12:23.320 回答