Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8194723
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T04:55:12+00:00 2026-06-07T04:55:12+00:00

Environment: 3 GB data file with a 28 byte SHA-1 checksum appended to the

  • 0

Environment:
3 GB data file with a 28 byte SHA-1 checksum appended to the end.

Is it possible to use a FileStream or some other type of stream to calculate a SHA-1 checksum hash by reading the stream from position 0 to position [x – 28(The length of the appended checksum)] without physically removing the appended checksum from the end of the file first?

Currently we are opening the file using a FileStream and then reading it using a BinaryReader to seek and read the last 28 bytes of the file.

Then opening the file again with a FileStream and setting the length of the stream to the length – 28 bytes and this is removing the checksum from the file.

Finally we are calculating a checksum of the data file with the last 28 bytes removed and then comparing it to the checksum we removed from the end of the file to ensure the checksums match.

Basically I want to know if it’s possible to calculate the checksum of the data part of the file without having to remove the appended checksum first.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T04:55:14+00:00Added an answer on June 7, 2026 at 4:55 am

    If you know how much data you really want to read (i.e. length – 28 bytes) then when you compute the hash, only put in that much data. You haven’t said exactly how you’re computing the hash, but you can generally repeatedly “write” more data into the hash computation – just do that for as long as you need, until you get to the last 28 bytes.

    Sample:

    public byte[] Sha1ExceptEnd(Stream input, int bytesToOmit)
    {
        long bytesToRead = input.Length - bytesToOmit;
        byte[] buffer = new byte[16 * 1024]; // Hash up to 16K at a time
        using (SHA1 sha1 = SHA1.Create())
        {
            while (bytesToRead > 0)
            {
                int thisPass = (int) Math.Min(buffer.Length, bytesToRead);
                int bytesReadThisPass = input.Read(buffer, 0, thisPass);
                if (bytesReadThisPass <= 0)
                {
                    throw new IOException("Unexpected end of data");
                }  
                sha1.TransformBlock(buffer, 0, bytesReadThisPass, buffer, 0);
                bytesToRead -= bytesReadThisPass;
            }
            // Flush the hash
            sha1.TransformFinalBlock(buffer, 0, 0);
            return sha1.Hash;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have been writing to Environment.SpecialFolder.ApplicationData this data file, that upon uninstall needs
I have lots of tables with statistical data (environment related) and wondering if there
My development environment at work is not sufficient to process ALL of the data
I am migrating our hosting environment to a totally new data center with new
I have a problem with MySql.Data in a partial trusted environment. I've added MySql.Data
I have rooted phone. I want to copy data/data/com.android.providers.telephony/databases/mmssms.db file to sd card programatically.
I have an application which is making use of the RSACryptoServiceProvider to decrypt some
I was able to use SQL Filestream fine locally but when I try to
I'm storing my data to a file in /data/data/.....! And i want to add
I want to copy a file from /data/data... to the external SDCARD! However, i'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.