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

  • SEARCH
  • Home
  • 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 6077115
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:41:04+00:00 2026-05-23T10:41:04+00:00

Currently I am implementing into my C++/CLI code a function that return the SHA1

  • 0

Currently I am implementing into my C++/CLI code a function that return the SHA1 value of a file. It is a Windows Forms application in Visual Studio.

I chose to implement the .NetFramework class SHA1CryptoServiceProvider because it is really fast (believe me). I have tested several algorithms but none of them were as fast as the SHA1CryptoServiceProvider class.

The problem is that in my application there is a progressBar showing the progress of computing SHA1 and the SHA1CryptoServiceProvider class doesn’t have any function that returns progress of computing SHA1.

Here is the code:

using namespace System::Security::Cryptography;
using namespace System::IO;

StreamReader^ Reader = gcnew StreamReader("C:\\abc.exe");
SHA1CryptoServiceProvider^ SHA1 = gcnew SHA1CryptoServiceProvider();

String^ Hash = "";

Hash = BitConverter::ToString(SHA1->ComputeHash(Reader->BaseStream));
return Hash;
  • 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-05-23T10:41:05+00:00Added an answer on May 23, 2026 at 10:41 am

    Finally I have done it. I post the code, maybe someone will find it useful. I know the code is not clean, I am still learning. It can compute SHA1 of files larger that 2^31 bytes. Tested it on a 22GB file. Works fine in backgroundWorker 🙂

    #define SHA1_BUFFER_SIZE  65535
    //input buffer
    array<unsigned char,1>^ buf = gcnew array<unsigned char,1>(SHA1_BUFFER_SIZE);
    pin_ptr<unsigned char> pointer = &buf[0];
    
    //Open file in 64-bit mode
    FILE *file = _fopeni64("some_large_file.txt","rb");
    SHA1CryptoServiceProvider^ SHA1 = gcnew SHA1CryptoServiceProvider();
    
    //Move pointer to End of File
    _fseeki64(file,0,SEEK_END);
    //Read pointer position (file size)
    unsigned __int64 size = (__int64)_ftelli64(file);
    
    // Move pointer to begining of file
    _fseeki64(file,0,SEEK_SET);
    __int64 i = 1;    // counter
    float wyn = 0;    // help variable for progress Percentage (float)
    __int64 conv = 0; // help variable for progress Percentage (int)
    
    //output buffer
    array<unsigned char,1>^ outputbuffer = gcnew array<unsigned char,1>(SHA1_BUFFER_SIZE);
    while(1)
    {
        //Read SHA1_BUFFER_SIZE bytes to buffer
        size_t bufLen = fread( pointer, 1, SHA1_BUFFER_SIZE, file );
        if (bufLen == 0) //End of file
        {
            if (ferror(file)) //Error opening file
                return;
            break;
        }
        //buffer has the last block of bytes of the file
        if ( SHA1_BUFFER_SIZE*i >= size  )
            SHA1->TransformFinalBlock(buf,0,bufLen);
        else
            SHA1->TransformBlock(buf,0,bufLen,outputbuffer,0);
    
        wyn = SHA1_BUFFER_SIZE*100; /* Getting    */
        wyn /= size;                /* the        */
        wyn *= i;                   /* progress   */
        conv = wyn;                 /* Percentage */
        ComputeSHA1->ReportProgress(conv);
        \\Update our progressBar
        i++;
    } //End main loop
    
    String^ sHash = "";
    //Get the computed hash and convert to System::String
    sHash = BitConverter::ToString(SHA1->Hash);
    //Replace the '-' characters in hash to white spaces
    sHash = sHash->Replace('-',' ');
    //Removing whitespaces from hash
    sHash = System::Text::RegularExpressions::Regex::Replace(sHash, "\\s+", System::String::Empty);
    
    //Filling a textBox with the SHA1
    ComputeSHA1->ReportProgress(0,sHash);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently working on a application that will be implementing user customizable widgets
I'm currently working on implementing Lua into one of the applications that I'm working
I'm currently implementing a profiling system into an application. I have a two macro
we are currently implementing logging functionality with Log4net into our ASP.NET web-services. Therefore we
I'm currently implementing a JavaScript library that keeps track of the history of changes
I'm currently implementing a HTML canvas based webapp that features panning. Is there a
I am currently implementing a method that accepts two bitmap objects. We can assume
I'm currently implementing some image processing code for Android. I'm aware of the memory
I'm currently implementing a software that measures certain values over time. The user may
I'm currently implementing Google Analytics into my app. The documentation says nothing about how

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.