SHA1 Hash question with large Files

M

Michael H

Hi all,

I guess I don't fully understand how a SHA1 hash value is calculated
in C# / .NET for a large file... I'm trying to calculate SHA1 values
for large files that are much larger than my physical main memory. It
seems the way to derive a SHA1 value involves opening a file stream to
the large file, passing it to a byte array, and passing the byte array
to the .NET hash method.

Does this load the entire file into main memory (within the byte[] )
??? I see hash values for DVD isos all the time and feel that there
must be a way to derive a hash value via passing a file stream to the
hash method whereas very low main memory consumption occurs.

Any help or pointers to documentation that addresses this would be
super great.


Thanks,


Mike.
 
G

Guest

Hi Michael,
SHA1 is a block cypher. Blocks of 512 bits are read in at a time and the
160bit hash is computed using the blocks, therefore it is not necesary to
read in the entire contents of the file into memory at once. The value is
continually computer from the individual blocks that are read in. you will
have to read inthe entire contents of hte file to produce the hash but there
is no need to have the entire file in memory at once to do this.

If you are interested in the internal workings the RFC is a good place to
look:
http://www.faqs.org/rfcs/rfc3174.html

Hope that helps
Mark R Dawson.
 
W

William Stacey [MVP]

One of the overloads for ComputeHash() takes a Stream object. Just pass the
file stream to this and it will run over the file and compute the hash
without loading it all into memory. You could do the same thing yourself
for a for loop, but it is already there. HTH
 
M

Michael H

On Thu, 28 Jul 2005 01:22:18 -0400, "William Stacey [MVP]"

--> One of the overloads for ComputeHash() takes a Stream object.
Just pass the
--> file stream to this and it will run over the file and compute the
hash
--> without loading it all into memory. You could do the same thing
yourself
--> for a for loop, but it is already there. HTH
-->
--> --
--> William Stacey [MVP]



How about using a Stream object to calculate a hash value for a file
on a mobile device running a Windows OS / .NET CF1.0 ?
 
W

William Stacey [MVP]

The docs say it is supported by Supported by the .NET Compact Framework. Is
this in error?
 
M

Michael H

On Fri, 29 Jul 2005 00:30:21 -0400, "William Stacey [MVP]"

--> The docs say it is supported by Supported by the .NET Compact
Framework. Is
--> this in error?
-->
--> --
--> William Stacey [MVP]


We may be looking at different things? Here's what I'm looking at:

**************
namespace: System.Security.Cryptography

[C#]
public byte[] ComputeHash( Stream inputStream )


Parameters
inputStream - The input for which to compute the hash code.

Return Value
The computed hash code.


Requirements
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition,
Windows 2000, Windows XP Home Edition, Windows XP Professional,
Windows Server 2003 family
****************

This isn't supported in CF1.0 on OpenNetCF1.3 right ?


Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top