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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:17:55+00:00 2026-05-26T05:17:55+00:00

In my project i need to get the MD_5 hash code of the file

  • 0

In my project i need to get the MD_5 hash code of the file in iphone. uptill now i have found the following code to get md_5 of any image/any file.

 -(NSString *)getMD5FromString:(NSString *)source{
    const char *src = [source UTF8String];
    unsigned char result[CC_MD5_DIGEST_LENGTH];
    CC_MD5(src, strlen(src), result);
    return [[NSString
    stringWithFormat: @"%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X",
        result[0], result[1],
        result[2], result[3],
        result[4], result[5],
        result[6], result[7],
        result[8], result[9],
        result[10], result[11],
        result[12], result[13],
        result[14], result[15]
        ]lowercaseString];
  }

using this code to get the ByteContent of the image and then get the md_5 of that image byte array string

 UIImage *image = [UIImage imageNamed:@"sf_small.png"];
 NSData *data = UIImagePNGRepresentation(image);
 NSString *str = [NSString stringWithFormat:@"%@",data];
 NSString *temp = [self getMD5FromString:str];

now i am getting a hash code succesfully But when on the web side i get the md_5 hash code of same file then it gives me diferent hash code. in Web side i am using PHP code

 md5_file(string $filename);

this PHP code gives me differnet hash code and iphone code gives me different hash code for same image. Please tell me what can be the problem..

Thanks alot!

tic.png

  • 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-26T05:17:56+00:00Added an answer on May 26, 2026 at 5:17 am

    There are 2 causes. The first is because the raw bytes → string → UTF-8 process corrupted some non-ASCII characters. Note that you can get a pointer to the bytes from an NSData directly:

    UIImage* image = [UIImage imageNamed:@"sf_small.png"];
    NSData* data = UIImagePNGRepresentation(image);
    
    const void* src = [data bytes];
    NSUInteger len = [data length];
    CC_MD5(src, len, result);
    ...
    

    The second cause is because of the PNG → raw image → PNG process. There is no guarentee that the same image will compress to the same PNG representation in different libraries, and of course you’ll have different MD5. You could just avoid reading the file as image altogether, as it’s possible read the file directly as data:

    NSData* data = [NSData dataWithContentsOfFile:@"sf_small.png"];
    
    const void* src = [data bytes];
    NSUInteger len = [data length];
    CC_MD5(src, len, result);
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to get a resource image file in a java project. What I'm
Requirement of my project is, if device have internet connectivity, need to get the
For a project I need to get the source code of web page of
I have the dynamically generated input values in my project. I need to get
I'm working in a project that need to get SVD (Single Values Decomposition) for
I'm working on a project where I need to get the total row count
i am working on a magento project and i need to get the value
I am working on a C# project where I need to get data from
I'm doing a Get and Post method for an android project and I need
The Junits I have in my project need to load property files from the

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.