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

  • Home
  • SEARCH
  • 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 744057
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T08:56:04+00:00 2026-05-14T08:56:04+00:00

I’m writing an OS X client for a software that is written in PHP.

  • 0

I’m writing an OS X client for a software that is written in PHP. This software uses a simple RPC interface to receive and execute commands. The RPC client has to sign the commands he sends to ensure that no MITM can modify any of them.

However, as the server was not accepting the signatures I sent from my OS X client, I started investigating and found out that PHP’s openssl_sign function generates a different signature for a given private key/data combination than the Objective-C SSCrypto framework (which is only a wrapper for the openssl lib):

SSCrypto *crypto = [[SSCrypto alloc] initWithPrivateKey:self.localPrivKey];
NSData *shaed = [self sha1:@"hello"];
[crypto setClearTextWithData:shaed];
NSData *data = [crypto sign];

generates a signature like CtbkSxvqNZ+mAN…

The PHP code

openssl_sign("hello", $signature, $privateKey);

generates a signature like 6u0d2qjFiMbZ+…
(For my certain key, of course. base64 encoded)

I’m not quite shure why this is happening and I unsuccessfully experimented with different hash-algorithms. As the PHP documentation states SHA1 is used by default.

So why do these two functions generate different signatures and how can I get my Objective-C part to generate a signature that PHPs openssl_verify will accept?

Note: I double checked that the keys and the data is correct!

  • 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-14T08:56:04+00:00Added an answer on May 14, 2026 at 8:56 am

    Okay, it took quite a few hours. Here’s what’s happening:

    When you call the openssl_sign function, PHP internally uses the EVP API that is provided by the openssl lib. EVP is a “high level” API to the underlying functions like RSA_private_encrypt. So when you call base64_encode(openssl_sign('hello', $signature, $privKey)) that’s similar to do something like this on the command line using the openssl binary:

    echo -n "hello"| openssl dgst -sha1 -sign priv.key | openssl enc -base64
    

    and NOT

    echo -n "hello" | openssl dgst -sha1 | openssl rsautl -encrypt priv.key | openssl enc -base64
    

    I don’t know why this produces different output , but it does. If someone has an idea why they differ: please share!
    However, as I’m using the SSCrypto framework I rewrote the -sign (and -verify) function with EVP calls (abstract):

    OpenSSL_add_all_digests();
    EVP_MD_CTX_init(&md_ctx);
    EVP_SignInit(&md_ctx, mdtype);
    EVP_SignUpdate(&md_ctx, input, inlen);
    if (EVP_SignFinal(&md_ctx, (unsigned char*) outbuf, (unsigned int *)&outlen, pkey)) {
        NSLog(@"signed successfully.");
    }
    

    And voila: I get the same signatures as I got from PHP. Oh and for the record: PHP uses the PKCS padding.

    Thank you guys for pointing me in the right direction!

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

Sidebar

Ask A Question

Stats

  • Questions 368k
  • Answers 368k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer $("li>a").each(function(i,el){ var id = $(this).attr("href").split("=")[1]; $(this).parent().attr("id", id); }) May 14, 2026 at 6:05 pm
  • Editorial Team
    Editorial Team added an answer $('#element-id').css('margin-left', function (index, curValue) { return parseInt(curValue, 10) + 100… May 14, 2026 at 6:05 pm
  • Editorial Team
    Editorial Team added an answer If the file is a Maven dependency, you could use… May 14, 2026 at 6:05 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.