我正在编写一个哈希密码的类,它通过使用System.Security.Cryptography.Rfc2898DeriveBytes类来生成用于计算哈希值的键来实现密钥拉伸.
代码基本上是这样的:
// Higher iterations value results in better key strength
var db = new Rfc2898DeriveBytes(password + salt + secretKeyFromConfigFile,
saltAsBytes,
iterations);
byte[] hashKey = db.GetBytes(64); // 64 bytes is the recommended size for the HMACSHA512 class
var sha512 = new System.Security.Cryptography.HMACSHA512(hashKey);
byte[] hashInput = System.Text.Encoding.UTF8.GetBytes(password + salt + secretKeyFromConfigFile);
byte[] hash = sha512.ComputeHash(hashInput);
return System.Convert.ToBase64String(hash);
Run Code Online (Sandbox Code Playgroud)
System.Security.Cryptography.Rfc2898DeriveBytes的文档表明它使用"...基于System.Security.Cryptography.HMACSHA1的伪随机数生成器"来派生密钥.
由于SHA512优于SHA1,所以简单地应用SHA512散列函数会更好吗?
byte[] hash;
for (int i = 0; i < iterations; i++)
{
hash = sha512.ComputeHash(hash ?? hashInput);
}
return System.Convert.ToBase64String(hash); …Run Code Online (Sandbox Code Playgroud) 以下第二种缩进方法的一般意见是什么?
// Normal indentation
a.Value = "foobar";
ab.Checked = false;
foo.Value = "foobar";
foobar.Checked = true;
// Spaces before the dot to align the properties/methods
a .Value = "foobar";
ab .Checked = false;
foo .Value = "foobar";
foobar.Checked = true;
Run Code Online (Sandbox Code Playgroud)
这应该是一个维基,但我要么没有足够的权限,要么不知道如何更改它.
编辑
我已经决定添加另一个例子来更好地展示这种缩进样式可能有用的地方.
fooA .PropertyA = true;
foobarB.PropertyA = true;
Run Code Online (Sandbox Code Playgroud)
使用VS2010中的新多线编辑功能,可以更轻松地更改所有线路上的PropertyA.
在C#中也有空格,甚至在点之前的换行并不罕见(参见LINQ).