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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T22:16:21+00:00 2026-06-03T22:16:21+00:00

I am using the commoncrypto library on the iPhone to create a pair of

  • 0

I am using the commoncrypto library on the iPhone to create a pair of RSA keys and I am trying to send the public key to a server (Python) so that I can use it to verify a signature sent from the phone.

I’m using the exact code from the CommonCrypto example using the method getPublicKeyBits() which looks like this:

`- (NSData )getPublicKeyBits {
OSStatus sanityCheck = noErr;
NSData
publicKeyBits = nil;
NSData* publicTag = [[NSData alloc] initWithBytes:publicKeyIdentifier length:sizeof(publicKeyIdentifier)];
CFDataRef cfresult = NULL;

NSMutableDictionary * queryPublicKey = [[NSMutableDictionary alloc] init];

// Set the public key query dictionary.
[queryPublicKey setObject:(__bridge id)kSecClassKey forKey:(__bridge id)kSecClass];
[queryPublicKey setObject:publicTag forKey:(__bridge id)kSecAttrApplicationTag];
[queryPublicKey setObject:(__bridge id)kSecAttrKeyTypeRSA forKey:(__bridge id)kSecAttrKeyType];
[queryPublicKey setObject:[NSNumber numberWithBool:YES] forKey:(__bridge id)kSecReturnData];

// Get the key bits.
sanityCheck = SecItemCopyMatching((__bridge CFDictionaryRef)queryPublicKey, (CFTypeRef*)&cfresult); 


if (sanityCheck != noErr)
{
    publicKeyBits = nil;
}
else 
{
    publicKeyBits = (__bridge_transfer NSData *)cfresult;
}

return publicKeyBits;

}`

The problem is that I don’t know how, exactly, the key is being stored or how to pass it. I am using the getPublicKeyBits() to get it in a NSData structure, and I’ve imported a library to encode it in base64. I’m getting a key (SHA1, I’d like to move to SHA256, but that’s secondary to getting this working) and the base64 version looks like other keys I’ve found here and in other people solving RSA problems.

I’ve been trying to use the M2Crypto library in Python and when I try to verify I’m getting the error "RSA Error: No Start Line". Here’s the code I’m using to receive the public key:

pubKey = request.form['publickey']

uid = uuid4().hex
while not unique(uid, User):
    uid = uuid.uuid4().hex
user = User(uid, email, secret, pubKey)

And the code I’m using to check the signature:

def validate(sessionKey, sig, pem):
    bio = BIO.MemoryBuffer(pem.encode('ascii'))
    rsa = RSA.load_pub_key_bio(bio)
    pubkey = EVP.PKey()
    pubkey.assign_rsa(rsa)

    pubkey.reset_context(md='sha1')
    pubkey.verify_init()
    pubkey.verify_update(sessionKey)

    return pubkey.verify_final(sig)

I’m really stumped as to what I’m doing wrong but I feel like I’m getting close. If my whole method is not the way you’d do it, I’d love to hear any other way to generate RSA keys on the phone, publish the public key to a server, and then verify a signature from the phone on that server.

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-03T22:16:22+00:00Added an answer on June 3, 2026 at 10:16 pm

    You can use the getPublicKeyBits method from SecKeyWrapper in the Apple CryptoExercise code

    https://developer.apple.com/library/ios/#samplecode/CryptoExercise/Listings/Classes_SecKeyWrapper_h.html

    This will get you the DER encoded binary data. Then use the following method to load it into M2Crypto in Python: (Basically, just base64 it and invoke one method.)

    https://stackoverflow.com/a/5765576/584616

    I have an ARC enabled version of this getPublicKeyBits method, but I haven’t gotten around to posting it yet.

    Update – on re-reading your question, the answer is actually here:

    How to find out the modulus and exponent of RSA Public Key on iPhone/Objective C

    You can use this to get the modulus and exponent as NSData, which you should be able to easily convert into base64 or your representation of choice.

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

Sidebar

Related Questions

I'm trying to use CommonCrypto to generate keys using PBKDF2 but I can't seem
Using Entity Framework CodeFirst, how do I create a created datetime column that gets
Using boost python I need create nested namespace. Assume I have following cpp class
Using Server.Transfer to show a page that informs the user that the web site
Using devise 2.1.0 I am trying to send the new registration page a PricingPlan
using (var file_stream = File.Create(users.xml)) { var serializer = new XmlSerializer(typeof(PasswordManager)); serializer.Serialize(file_stream, this); file_stream.Close();
Using Nunit, I want to be able to write a test fixture that will
Using top it's easy to identify processes that are hogging memory and cpu, but
I am using CommonCrypto for encryption on Mac OS 10.7. Isn't this framework built
Using linq2sql I'm trying to take the string in txtOilChange and update the oilChange

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.