Csharp/C Sharp by API/System.Security.Cryptography/KeyedHashAlgorithm — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Версия 18:31, 26 мая 2010
KeyedHashAlgorithm.ComputeHash
<source lang="csharp">
using System; using System.IO; using System.Text; using System.Security.Cryptography; class MainClass {
public static void Main(string[] args) { byte[] key = Encoding.Unicode.GetBytes(args[2]); using (KeyedHashAlgorithm hashAlg = KeyedHashAlgorithm.Create(args[1])) { hashAlg.Key = key; using (Stream file = new FileStream(args[0], FileMode.Open, FileAccess.Read)) { byte[] hash = hashAlg.ruputeHash(file); Console.WriteLine(BitConverter.ToString(hash)); } } }
}
</source>
KeyedHashAlgorithm.Create
<source lang="csharp">
using System; using System.IO; using System.Text; using System.Security.Cryptography; class MainClass {
public static void Main(string[] args) { byte[] key = Encoding.Unicode.GetBytes(args[2]); using (KeyedHashAlgorithm hashAlg = KeyedHashAlgorithm.Create(args[1])) { hashAlg.Key = key; using (Stream file = new FileStream(args[0], FileMode.Open, FileAccess.Read)) { byte[] hash = hashAlg.ruputeHash(file); Console.WriteLine(BitConverter.ToString(hash)); } } }
}
</source>