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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T03:37:24+00:00 2026-06-02T03:37:24+00:00

I am trying to communicate with a C# service from a native iPhone application.

  • 0

I am trying to communicate with a C# service from a native iPhone application. In order to communicate the password entered needs to be hashed and compared against the hashed version that is stored on the server. I am attempting to recreate the C# hash in Objective C and that’s where it starts to get interesting

Objective C Code:

NSString * password = @"testPass123";
const char *cPassword = [password UTF8String];    

NSString * key = @"Garbage12345";
NSData * keyData = [NSData dataFromBase64String:key];
NSUInteger len = [keyData length];
unsigned char * cKey = (unsigned char *)malloc(len);
memcpy(cKey, [keyData bytes], len);

// Concatenate into one byte array
unsigned char totalString[18];
for (int i = 0; i < strlen(cPassword); i++) {
    totalString[i] = cPassword[i];
}

for (int i = 0; i < len; i++) {
    totalString[strlen(cPassword) + i] = cKey[i];
}

// DEBUG: Display byte array
for (int i = 0; i < 18; i++) {
    NSLog(@"totalString: %x", totalString[i]);
}

// **** totalString == plainTextWithSaltBytes from the C# portion ****
unsigned char result[CC_MD5_DIGEST_LENGTH];
CC_MD5(totalString, CC_MD5_DIGEST_LENGTH, result);

for (int i = 0; i < CC_MD5_DIGEST_LENGTH; i++) {
    NSLog(@"result: %02x", result[i]);
}

C# Code:

byte[] SaltBytes = Convert.FromBase64String("Garbage12345");

// Convert plain text into a byte array.
byte[] plainTextBytes = Encoding.UTF8.GetBytes("testPass123");

// Allocate array, which will hold plain text and salt.
byte[] plainTextWithSaltBytes = new byte[plainTextBytes.Length + SaltBytes.Length];

// Copy plain text bytes into resulting array.
for (int i = 0; i < plainTextBytes.Length; i++)
    plainTextWithSaltBytes[i] = plainTextBytes[i];

// Append salt bytes to the resulting array.
for (int i = 0; i < SaltBytes.Length; i++)
    plainTextWithSaltBytes[plainTextBytes.Length + i] = SaltBytes[i];

HashAlgorithm hash = new MD5CryptoServiceProvider();

// **** plainTextWithSaltBytes == totalString from the Obj-C portion ****
// Compute hash value of our plain text with appended salt.
byte[] hashBytes = hash.ComputeHash(plainTextWithSaltBytes);

// Convert result into a base64-encoded string.
string hashValue = Convert.ToBase64String(hashBytes);

I get back the same results for the byte array before it goes into the MD5 portion of either. Using the dummy data supplied it returns:

74
65
73
74
50
61
73
73
31
32
33
19
aa
db
6a
07
b5
db

However, afterwards I get back different values and am not sure where to go from there.

Anyone have any ideas? Feel free to point out things I’m doing wrong as well. Thanks.

  • 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-02T03:37:26+00:00Added an answer on June 2, 2026 at 3:37 am

    I suspect your bug is that the second parameter of CC_MD5 should be the input and not the output length. Passing in the input length should fix your immediate problem.

    But I think, that you should throw away the code on both sides, and use some function designed for password hashing. Such as PBKDF2 or bcrypt.

    It’s also strange that you send the hash to the server. Normally you send the password to the server and hash it there. Sending the hash essentially changed the definition of the password, and allows login for an attacker who doesn’t know the password but knows the hash.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to communicate with RIA service from extjs using POST for getting
I'm trying to get a IBinder from a Service so I can communicate with
I am trying to communicate/update UI from Service to activity. The broadcast I receive
I'm trying to communicate with SalesForce from Biztalk. To make a POC where I
I am trying to use twit in Meteor in order to communicate to the
I'm trying to communicate between a flex 4.1 application to a flash action script
I'm trying to figure out how to forward web service requests from the web
I am trying to communicate to database from JavaScript using AJAX. I have followed
I am trying to communicate with Google's spell check service using jQuery. Google's service
I get a warning trying to add a Cloud Service Reference from another project

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.