Непрерывная MD5
От: Аноним  
Дата: 22.02.05 22:24
Оценка:
Добрый день,

Стоит задача посчтиать MD5 по большому объему данных поэтому ComputeHash не подходит
Можно ли считать MD5 побайтно и учитытывать предыдущее значение для рассчета текущего...
То есть что то типа


while(...)
md5.ComputeByte(bufferByte);

// ...

byte[] result = md5,GetHash()
Re: Непрерывная MD5
От: Аноним  
Дата: 23.02.05 22:09
Оценка:
Здравствуйте, Аноним, Вы писали:

А>Добрый день,


А>Стоит задача посчтиать MD5 по большому объему данных поэтому ComputeHash не подходит

А>Можно ли считать MD5 побайтно и учитытывать предыдущее значение для рассчета текущего...
А>То есть что то типа


А>
А>while(...)
А>md5.ComputeByte(bufferByte);

А>// ...

А>byte[] result = md5,GetHash()
А>



неужели никто не знает???
Re[2]: Непрерывная MD5
От: TK Лес кывт.рф
Дата: 24.02.05 07:24
Оценка:
>
>
> неужели никто не знает???

Считай поблочно. Первый раз считаешь хеш для 1K, после этого начинаешь считать хеш для 1K + значение предыдущего хеша.
Posted via RSDN NNTP Server 2.0 alpha
Если у Вас нет паранойи, то это еще не значит, что они за Вами не следят.
Непрерывная MD5
От: Аноним  
Дата: 22.02.05 23:08
Оценка:
Вот есть такая утилитка для хэширования файлов. Может пригодится. (Консольное приложение).
 using System;
    using System.Security.Cryptography;
    using System.IO;
    using System.Text;
    namespace md5sum
    {
     class Class
     {
      [STAThread]
      static void Main(string[] args)
      {
       if(args.Length == 0)
       {
        Console.WriteLine("using mode:\n\t md5sum [filename] -> In order to compute MD5 hash\n\tmd5sum -c [filename] [md5file] -> Check a file integrity with an MD5 hash stored in a file\n\tmd5sum -o [in] -> Compute the MD5 Hash of a file and stores it in a file");
        return;
       }
       if(!args[0].StartsWith("-"))
       {
        FileStream fs = new FileStream(args[0],FileMode.Open);
        MD5 md5 = MD5.Create();
        byte[] hash = md5.ComputeHash(fs);
        string shash = "";
        foreach(byte b in hash)
        {
         shash += b.ToString("x");
        }
        Console.WriteLine("MD5 Hash: {0}",shash);
        return;
       }
       else
       {
        if(args[0].Equals("-c") || args[0].Equals("-C"))
        {
         //Get md5 hash stored in the file and compares it.
         string inf, hashf;
         if(args[1] != null)
         {
          inf = args[1];
         }else
         {
          Console.WriteLine("using mode:\n\t md5sum [filename] -> In order to compute MD5 hash\n\tmd5sum -c [filename] [md5file] -> Check a file integrity with an MD5 hash stored in a file\n\tmd5sum -o [in] -> Compute the MD5 Hash of a file and stores it in a file");
          return;
         }
         if(args[2] != null)
         {
          hashf = args[2];
         }else
         {
          Console.WriteLine("using mode:\n\t md5sum [filename] -> In order to compute MD5 hash\n\tmd5sum -c [filename] [md5file] -> Check a file integrity with an MD5 hash stored in a file\n\tmd5sum -o [in] -> Compute the MD5 Hash of a file and stores it in a file");
          return;
         }
         bool areEqual = Compare(inf,hashf);
         if(areEqual)
          Console.WriteLine("The file is OK");
         else
          Console.WriteLine("The file is NOT OK");
        }
        else if(args[0].Equals("-o") || args[0].Equals("-O"))
        {
         string inf;
         if(args[1] != null)
         {
          inf = args[1];
         }else
         {
          Console.WriteLine("using mode:\n\t md5sum [filename] -> In order to compute MD5 hash\n\tmd5sum -c [filename] [md5file] -> Check a file integrity with an MD5 hash stored in a file\n\tmd5sum -o [in] -> Compute the MD5 Hash of a file and stores it in a file");
          return;
         }
         HashtoFile(inf);
        }
       }
      }
      private static bool Compare(string infile, string hashfile)
      {
       FileStream fs1 = new FileStream(infile,FileMode.Open); //File to get hash code
       //Read MD5 Hash stored in fs2
       string shash2 = "";
       string tmp = "";
       try
       {
        StreamReader sr = new StreamReader(hashfile);
        
        while((tmp = sr.ReadLine()) != null)
        {
         if(!tmp.StartsWith(";"))
         {
          shash2 = tmp;
          break;
         }
        }
       }catch(Exception e)
       {
        Console.WriteLine("An Exception has ocurred: {0}",e.Message);
       }
       MD5 md5 = MD5.Create();
       byte[] hash = md5.ComputeHash(fs1);
       string shash = "";
       foreach(byte b in hash)
       {
        shash += b.ToString("x");
       }
       //Compare both values
       if(shash2.Equals(shash))
        return true;
       return false;
      }
      private static void HashtoFile(string infile)
      {
       FileStream fs1 = new FileStream(infile,FileMode.Open);
       string shash = "";
       byte[] hash;
       MD5 md5 = MD5.Create();
       hash = md5.ComputeHash(fs1);
       foreach(byte b in hash)
       {
        shash += b.ToString("x");
       }
       try
       {
        StreamWriter sw = File.CreateText(infile + ".md5");
        sw.WriteLine(";MD5 signature created with md5sum by Pablo Gonzalez");
        sw.WriteLine(";Begin MD5 signature");
        sw.WriteLine(shash);
        sw.WriteLine(";End of MD5 signature");
        sw.Close();
       }catch(Exception e)
       {
        Console.WriteLine("An Exception has ocurred: {0}",e.Message);
       }
      }
     }
    }
--
VBSTREETS, Editor-in-Chief
http://blogs.gotdotnet.ru/personal/gaidar/


данное сообщение получено с www.gotdotnet.ru
ссылка на оригинальное сообщение
Re: Непрерывная MD5
От: Аноним  
Дата: 23.02.05 22:37
Оценка:
Так... Значит RSDN все-таки посты не забирает. Жаль...
--
VBSTREETS, Editor-in-Chief
http://blogs.gotdotnet.ru/personal/gaidar/


данное сообщение получено с www.gotdotnet.ru
ссылка на оригинальное сообщение
Re[2]: Непрерывная MD5
От: TK Лес кывт.рф
Дата: 25.02.05 18:22
Оценка:
Hello, "gaidar"
> Так... Значит RSDN все-таки посты не забирает. Жаль...
>
Забирает. Только, мы никуда не торопимся
Posted via RSDN NNTP Server 2.0 alpha
Если у Вас нет паранойи, то это еще не значит, что они за Вами не следят.
Re: Непрерывная MD5
От: Serginio1 СССР https://habrahabr.ru/users/serginio1/topics/
Дата: 25.02.05 18:37
Оценка:
Здравствуйте, <Аноним>, Вы писали:

Посмотри реализацию

public byte[] ComputeHash(Stream inputStream)
{
      int num1;
      if (this.m_bDisposed)
      {
            throw new ObjectDisposedException(null, Environment.GetResourceString("ObjectDisposed_Generic_ObjectName1"));
      }
      byte[] buffer1 = new byte[0x400];
      do
      {
            num1 = inputStream.Read(buffer1, 0, 0x400);
            if (num1 > 0)
            {
                  this.HashCore(buffer1, 0, num1);
            }
      }
      while (num1 > 0);
      this.HashValue = this.HashFinal();
      byte[] buffer2 = (byte[]) this.HashValue.Clone();
      this.Initialize();
      return buffer2;
}
... << RSDN@Home 1.1.4 beta 4 rev. 303>>
и солнце б утром не вставало, когда бы не было меня
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.