C#字节[][]SHA1
我用C#编写了这段代码,它使用IKVM利用Java的SHA1加密C#字节[][]SHA1,c#,byte,sha1,C#,Byte,Sha1,我用C#编写了这段代码,它使用IKVM利用Java的SHA1加密 public static string ComputeHash(params byte[][] bytes) { if (bytes == null) throw new ArgumentNullException("bytes"); MessageDigest digest = MessageDigest.getInstance("SHA-1"); foreach
public static string ComputeHash(params byte[][] bytes)
{
if (bytes == null) throw new ArgumentNullException("bytes");
MessageDigest digest = MessageDigest.getInstance("SHA-1");
foreach (var item in bytes)
{
if (item == null)
if (bytes == null) throw new ArgumentNullException("bytes", "Inner array is null");
digest.update(item);
}
string s = (new java.math.BigInteger(digest.digest())).toString(16);
return s;
}
有没有替代IKVM的方法?如果我正确理解了这个问题,您可以使用System.Security.Cryptography中的类 下面是该页面中的代码示例:
byte[] data = new byte[DATA_SIZE];
byte[] result;
SHA1 sha = new SHA1CryptoServiceProvider();
// This is one implementation of the abstract class SHA1.
result = sha.ComputeHash(data);
我不认为将该示例更改为采用锯齿数组的示例会太难。感谢您的建议,我将对此进行更深入的研究。有点吹毛求疵:SHA-1是加密哈希函数,而不是加密。