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 6541949
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:10:02+00:00 2026-05-25T11:10:02+00:00

I have some problems with the SHA1 hash value of a string. I’m trying

  • 0

I have some problems with the SHA1 hash value of a string. I’m trying to send a file from a client written in VB.net to a server written in PHP. My problem is that when I pass the same string to VB.net and PHP, the SHA1 value calculated by VB.net is completely different from the value calculated by PHP.

For example, I want to encode a string in Base64 and then calculate the SHA1 Hash of the Base64 string. When the computer executes this task from the vb.net version and from the PHP version I get two different SHA1 values, even if apparently the Base64 encoded string is the same:

VB.net: 2E97A53B09C482A831540B532845BCAC79BFACCF
PHP: 350A2080264E2724D4BCBC521C35264D264A1DAF

I’m surely missing something, could you point me in the right direction and tell me what I’m doing wrong here?

Thank you very much

Here’s the VB.net Code:

Dim cInput As String
Dim cBase64 As String
Dim objSHA1 As New SHA1CryptoServiceProvider()
Dim abBytesToHash() As Byte
Dim cHash As String


cInput = "the quick brown fox jumps over the lazy dog"
cBase64 = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(cInput))

abBytesToHash = System.Text.Encoding.ASCII.GetBytes(cBase64)

abBytesToHash = objSHA1.ComputeHash(abBytesToHash)
cHash = BitConverter.ToString(objSHA1.ComputeHash(abBytesToHash))
cHash = Replace(cHash, "-", "")

MsgBox("BASE64: " + cBase64 + vbNewLine + "SHA1: " + cHash)

' Result is:
' BASE64: dGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIHRoZSBsYXp5IGRvZw==
' SHA1: 2E97A53B09C482A831540B532845BCAC79BFACCF

And here’s the PHP Code:

$cInput = "the quick brown fox jumps over the lazy dog";
$cBase64 = base64_encode($cInput);

echo("BASE64: " . $cBase64 . "<br />" . "SHA1: " . strtoupper(sha1($cBase64)));

// Result is:
// BASE64: dGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIHRoZSBsYXp5IGRvZw==
// SHA1: 350A2080264E2724D4BCBC521C35264D264A1DAF
  • 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-25T11:10:02+00:00Added an answer on May 25, 2026 at 11:10 am

    Well, the problem is that you’re double hashing in .NET and only single hashing in PHP. Here’s what you’re doing in .NET translated into PHP:

    $cInput = "the quick brown fox jumps over the lazy dog";
    $cBase64 = base64_encode($cInput);
    
    $sha = sha1($cBase64, true); // The true param returns the raw bytes instead of hex
    $chash = sha1($sha);
    

    So you’re double hashing it. To fix it, you just need to change your algorithm to:

    cInput = "the quick brown fox jumps over the lazy dog"
    cBase64 = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(cInput))
    
    abBytesToHash = System.Text.Encoding.ASCII.GetBytes(cBase64)
    
    cHash = BitConverter.ToString(objSHA1.ComputeHash(abBytesToHash))
    cHash = Replace(cHash, "-", "")
    

    Note that all I did was remove the abBytesToHash = objSHA1.ComputeHash(abBytesToHash) line…

    Alternatively, you could change the PHP to do this:

    $cInput = "the quick brown fox jumps over the lazy dog";
    $cBase64 = base64_encode($cInput);
    
    echo "BASE64: " . $cBase64 . "<br />";
    echo "SHA1: " . strtoupper(sha1(sha1($cBase64, true)));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Cocoa app send some data along with a SHA1 hash of
i have some problems with rowspan: var doc1 = new Document(); doc1.SetPageSize(PageSize.A4.Rotate()); string path
I have some problems to pass message from background page to my content_script.js. I
I have some problems sending mails through SMTP using Spring's MailSender interface and the
I have some problems with OpenCV s cvCanny(...) and the Image data types it
I have some problems sending an id though jquery. I have a form select
I have some problems with mod_rewrited at .httacess. We have created a website, the
I have some problems to start programming using cocos2D on linux + android. I
I have some problems with controlling a while loop inside an event structure. Say
I have some problems with a java app i'm developing, i'm using HtmlCleaner 2.2

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.