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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T09:30:34+00:00 2026-06-02T09:30:34+00:00

I have compiled and built openssl to my iOS project, but struggling in objective-c

  • 0

I have compiled and built openssl to my iOS project,

but struggling in objective-c with writing an equivalent code to this command line:

openssl rsautl -encrypt -inkey publicKey.pem -pubin -in textfile.txt -out encrypted.bin

How can I achieve this?

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

    So I resolved my problem, here is the function to my question that encrypts an NSString:

    I modified the code from the code in this question: send RSA public key to iphone and use it to encrypt

    (Also at the end of my code I use QSUtilities to encode the message in base64)

    #pragma mark Encryption using OpenSSL
    + (NSString *)EncryptMessage:(NSString *)message {
    NSString *path = [[NSBundle mainBundle] pathForResource:@"pubkey" ofType:@"pem"];
    FILE *pubkey = fopen([path cStringUsingEncoding:1], "r");
    if (pubkey == NULL) {
        NSLog(@"duh: %@", [path stringByAppendingString:@" not found"]);
        return NULL;
    }
    
    RSA *rsa = PEM_read_RSA_PUBKEY(pubkey, NULL, NULL, NULL);
    if (rsa == NULL) {
        NSLog(@"Error reading RSA public key.");
        return NULL;
    }
    
    const char *msgInChar = [message UTF8String];
    unsigned char *encrypted = (unsigned char *) malloc(512); //I'm not so sure about this size
    int bufferSize = RSA_public_encrypt(strlen(msgInChar), (unsigned char *)msgInChar, encrypted, rsa, RSA_PKCS1_PADDING);
    if (bufferSize == -1) {
        NSLog(@"Encryption failed");
        return NULL;
    }
    
    NSData *data = [NSData dataWithBytes:(const void *)encrypted length:512]; //I'm not so sure about this length
    NSString *result = [QSStrings encodeBase64WithData:data];
    
    free(rsa);
    fclose(pubkey);
    free(encrypted);
    
    return result;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have compiled and built a DLL project in VS 2010. I have an
I have a libfoo.so library built from C++ code (compiled with gcc), and I
I have an iOS project that is built upon a framework project that we
I have compiled a .NET application using Any CPU option. This .NET application uses
We have a set of assemblies that have been compiled as.Net 3.5 (built using
I have an iOS app built since the beginning with an error in it.
I have some code below that is accessing the registry. The application is built
I am using OpenCV 2.2 compiled and built from source for iOS. I used
I have a little project, and I want to have 2 compiled versions of
I have compiled wpa_supplicant code downloaded from http://hostap.epitest.fi/wpa_supplicant/ version is 0.7.3. I am getting

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.