如果我在 SQL Server 中运行以下命令:
SELECT HASHBYTES('SHA2_512', 'THE CAT SAT ON THE MAT')
然后在 C# 中运行它
string test = WordFunctions.SHA512("THE CAT SAT ON THE MAT");
我得到了相同的价值,这很棒。但是,如果我在 C# 代码中传递一个字符串变量,则如下所示:
string words = "THE CAT SAT ON THE MAT"
byte[] test
test = WordFunctions.SHA512(words);
那么我没有得到相同的价值?!
有任何想法吗?
SHA512 函数如下所示:
public static byte[] SHA512(String plaintext)
{
// convert the passPhrase string into a byte array
ASCIIEncoding AE = new ASCIIEncoding();
byte[] passBuff = AE.GetBytes(plaintext);
SHA512Managed hashVal = new SHA512Managed();
byte[] passHash = hashVal.ComputeHash(passBuff);
return passHash;
}