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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T00:20:46+00:00 2026-06-06T00:20:46+00:00

I’m new to this topic so sorry if this is a stupid question :\

  • 0

I’m new to this topic so sorry if this is a stupid question :\

I’m trying to decrypt a message with a given public key. Both the message and public key is given from the webservice.

See the following code for how i currently do the decrypting:

 for (NSValue *refVal in keyRefs) {
    SecKeyRef p_key = NULL;
    [refVal getValue:&p_key];
    if (p_key == NULL) continue;

    size_t dataLength = encryptedData.length;
    size_t outPutLength = MAX(dataLength, SecKeyGetBlockSize(p_key));

    void *outPutBuf = malloc(outPutLength);
    if (outPutBuf) {

        //  Error handling
        OSStatus status = SecKeyDecrypt(p_key,
                                        kSecPaddingNone,
                                        encryptedData.bytes,
                                        encryptedData.length,
                                        outPutBuf,
                                        &outPutLength
                                        );


        NSLog(@"decryption result code: %ld (size: %lu)", status, outPutLength);
        NSLog(@"FINAL decrypted text: %s", outPutBuf);

        if (status == errSecSuccess) {
            break;
        }
    } else {

        //Error handling
    }
}

I get no errors, but the decrypted string is displayed like this (the correct output should be a JSON array):

decryption result code: 0 size:511)  
FINAL decrypted text: ˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇˇ

Is it because I use the “SecKeyDecrypt” with a “public key” instead of a “private key”? In that case, what should i instead use for decrypting?

Thanks for any help regarding this!

EDIT: I’m using code from: http://blog.flirble.org/2011/01/05/rsa-public-key-openssl-ios/ to use the public key i get from the server (this is where “keyRefs” from the code snippet comes from)

  • 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-06T00:20:48+00:00Added an answer on June 6, 2026 at 12:20 am

    Of course, the public key is something someone else uses to encrypt data so that only someone with the private key can decrypt it.

    The very definition of a public key is that you can give it to anyone. You wouldn’t want anyone to be able to decrypt anyone else’s encrypted message would you?

    It is impossible to tell from your code fragment where your private key is stored, or what the contents (or even class) of keyRefs is.

    EDIT: In response to above OP’s comment. And clarification.

    *”The public key itself is the public part of a RSA-key-pair stored on the server. The encrypted message was created on the server by first JSON-encoding the object, then encrypted with the private-key with OPENSSL_PKCS1_PADDING, then base64-encoded, and then JSON-encoded again as a part of the final message. The message and public key is stored on the client. What i want is to decrypt the message on the client by using the public key. As i said, im not very good at this subject so i might have tried to do this the wrong way”*

    Thats not how public key cryptography works. The server and client exchange public keys. Then each of them use the other’s public key to encrypt data sent to the opposite party. The receiving party always uses their own private key to decrypt the message.

    If you want the server to generate an encrypted response, have the client pass their public key in the request, use that public key to encrypt the response, and then decrypt the response on the client with the client’s private key.

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

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
this is what i have right now Drawing an RSS feed into the php,
I am trying to render a haml file in a javascript response like so:

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.