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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T02:37:57+00:00 2026-06-10T02:37:57+00:00

So I have an odd little problem with the hashing function in PHP. It

  • 0

So I have an odd little problem with the hashing function in PHP. It only happens some of the time, which is what is confusing me. Essentially, I have a Java app and a PHP page, both of which calculate the SHA256 of the same string. There hasn’t been any issues across the two, as they calculate the same hash (generally). The one exception is that every once in a while, PHP’s output is one character longer than Java’s.

I have this code in PHP:

$token = $_GET["token"];
$token = hash("sha256", $token."<salt>");
echo "Your token is " . $token;

99% of the time, I get the right hash. But every once in a while, I get something like this (space added to show the difference):

26be60ec9a36f217df83834939cbefa33ac798776977c1970f6c38ba1cf92e92 # PHP
26be60ec9a36f217df83834939cbefa33ac798776977c197 f6c38ba1cf92e92 # Java

As you can see, they’re nearly identical. But the top one (computed by PHP) has one more 0 for some reason. I haven’t really noticed a rhyme or reason to it, but it’s certainly stumped me. I’ve tried thinking of things like the wrong encoding, or wrong return value, but none of them really explain why they’re almost identical except for that one character.

Any help on this issue would be much appreciated.

EDIT: The space is only in the bottom one to highlight where the extra 0 is. The actual hash has no space, and is indeed a valid hash, as it’s the same one that Java produces.

EDIT2: Sorry about that. I checked the lengths with Notepad++, and since it’s different than my normal text editor, I misread the length by 1. So yes, the top one is indeed right. Which means that it’s a bug in my Java code. I’m going to explore Ignacio’s answer and get back to you.

  • 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-10T02:37:59+00:00Added an answer on June 10, 2026 at 2:37 am

    The top hash is the correct length; the bottom hash is output because the hexadecimal values were not zero-filled on output (note that it’s the MSn of a byte). So, a bug in the Java program unrelated to the hash algorithm.

    >>> '%04x %02x%02x %x%x' % (0x1201, 0x12, 0x01, 0x12, 0x01)
    '1201 1201 121'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm actually translating some C++ code (which I know very little about, and have
So, I have a little code that doesn't work for some odd reason. It's
Little trouble in using css, in the below code, i have used odd and
I have odd problem: After starting server I got this error: undefined local variable
I have an odd problem with Django. I have a set of objects that
I have an odd situation in which I need to modify the position of
I have an odd problem where Hibernate is running more queries than I've asked
I have a really odd behavior here: I created a little popup dialog in
I have come across something a little odd. I as trying to use the
I have a problem with an inherited database for which the person who originally

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.