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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:55:25+00:00 2026-05-27T00:55:25+00:00

I am trying to create a md5 hash that I am comparing against a

  • 0

I am trying to create a md5 hash that I am comparing against a php md5 hash.

The two don’t seam to be the same

below is my c code along with the php compairison

Why are the two md5 not the same?

Make command

gcc -Wall -lssl  -o test test.c

Code test.c

#include <stdio.h>
#include <openssl/md5.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <openssl/md5.h>
#include <time.h>

unsigned char result[MD5_DIGEST_LENGTH];

// Print the MD5 sum as hex-digits.
void print_md5_sum(unsigned char* md, char* md5) {

    int i;

    for(i=0; i < MD5_DIGEST_LENGTH; i++) {

            char temp[3];
            snprintf(temp,sizeof(temp),"%02x",md[i]);

            if(i == 0){
                    strncpy(md5,temp,3);
            }else{
                    strncat(md5,temp,MD5_DIGEST_LENGTH);
            }
    }

        printf("md5 is %s \n", md5);
}

int main(int argc, char** argv ){

    char* file_buffer = "testtest";
    char buffer[MD5_DIGEST_LENGTH +1];

    MD5((unsigned char*) file_buffer, sizeof(file_buffer), result);

    printf("length %i\n", MD5_DIGEST_LENGTH);

        print_md5_sum(result,buffer);
        printf("%s \n" ,buffer);

        return 0;
}

php code

<?php
    echo md5("testtest");
?>

results

php md5

05a671c66aefea124cc08b76ea6d30bb

c code md5

098f6bcd4621d373cade4e832627b4f6
  • 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-27T00:55:25+00:00Added an answer on May 27, 2026 at 12:55 am

    sizeof(file_buffer) does not give you the correct length to calculate the MD5 sum over. It only gives you the size of the pointer file_buffer, which will be likely either 4 or 8 depending on your platform.

    In this case you are probably better calling the MD5() function like this:

    MD5((unsigned char*) file_buffer, strlen(file_buffer), result);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create an md5 value in php using the instruction given.
I'm currently trying to create a mySQL database that holds hashes such as MD5
I am trying to create a user using code. I have the following that
I am trying to create a md5 hash for a string but the problem
I am trying to create an android MD5 hash string to equal the C#
I am trying to generate a Unix-Style password hash using MD5. I undestand that
I am trying create a WCF service that leverages the WPF MediaPlayer on the
Trying to create my first iPhone app that would play back audio. When I
Trying to create a small monitor application that displays current internet usage as percentage
I'm trying to connect to a website I made with auth that uses MD5.hex(password)

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.