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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T13:37:48+00:00 2026-05-11T13:37:48+00:00

I have a Cocoa app send some data along with a SHA1 hash of

  • 0

I have a Cocoa app send some data along with a SHA1 hash of that data to a Rails app which verifies that the data and the hash match, but they do not.

To be sure I have logged hex versions of the data that is hashed to the console at both the Rails and Cocoa sides, and they match exactly.

Here’s the Cocoa part:

#import <CommonCrypto/CommonDigest.h>  //...  - (NSData *)dataOfSHA1Hash {     unsigned char hashBytes[CC_SHA1_DIGEST_LENGTH];     CC_SHA1([self bytes], CC_SHA1_DIGEST_LENGTH, hashBytes);      return [NSData dataWithBytes:hashBytes length:CC_SHA1_DIGEST_LENGTH]; }  //...  NSData *signatureData = [signedData dataOfSHA1Hash]; NSString *signature = [signatureData hexadecimalString]; 

..and Rails:

Digest::SHA1.hexdigest(signed_data) 

Note that -hexadecimalString is a custom extension to NSData (didn’t seem to be built in), which I’ve tested. That method does not seem to be the problem.

So, why don’t my SHA1 hashes match on the same data? Any ideas?

Edit: example

For the string ‘Hello World!’

Cocoa: f98ee9c814c2f3c66ccdca641298d12cd26741ec Rails: 2ef7bde608ce5404e97d5f042f95f89f1c232871

Cocoa:

NSMutableData *signedData = [[NSMutableData alloc] init]; [signedData appendData:[@'Hello World!' dataUsingEncoding:NSUTF8StringEncoding]];  NSData *signatureData = [signedData dataOfSHA1Hash]; [signedData release]; NSString *signature = [signatureData hexadecimalString];  NSLog(@'Signature: %@', signature); // output: Signature: f98ee9c814c2f3c66ccdca641298d12cd26741ec 

Ruby:

>> Digest::SHA1.hexdigest('Hello World!') => '2ef7bde608ce5404e97d5f042f95f89f1c232871' 
  • 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. 2026-05-11T13:37:49+00:00Added an answer on May 11, 2026 at 1:37 pm

    Found the error, stupid little thing:

    -CC_SHA1([self bytes], CC_SHA1_DIGEST_LENGTH, hashBytes); +CC_SHA1([self bytes], [self length], hashBytes); 

    I sent the length of the digest instead of the length of the data. Don’t know how I could’ve made such a mistake – and then overlook it for hours.

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

Sidebar

Related Questions

Environment: xcode 3.2.1, document-based core-data application. I have a document-based cocoa app which uses
I have a Cocoa app that does a number of things, but among them,
I have a basic Cocoa app with a custom NSCollectionView that overrides drawRect: to
I have a graphics editing cocoa app on Mac OSX that produces 32 by
I have a button in my Cocoa app that opens a url in the
I have a very simple Mac Cocoa app that just has a Web View
I have a Cocoa app with a ManMenu.xib, in which the main menu is
I have a Cocoa app which interacts with a server and displays a GUI.
I have created Cocoa app which is type of launch agent. To distribute this
I have a MainViewController in my Cocoa Touch app which shows a status view

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.