Tom Irving
Tom Irving

Reputation: 10059

RSA encryption in Objective-C (Mac)

I'm hacking around on stuff that requires RSA encryption and I've got some code which looks like this:

- (NSData *)RSAEncryptData:(NSData *)data {

    NSMutableData * encrypted = [NSMutableData dataWithLength:256];

    RSA * rsa = RSA_new();
    rsa->n = BN_bin2bn(modulus.bytes, modulus.length, NULL);
    rsa->e = BN_bin2bn(exponent.bytes, exponent.length, NULL);

    RSA_public_encrypt(data.length, data.bytes, encrypted.mutableBytes, rsa, RSA_PKCS1_OAEP_PADDING);
    RSA_free(rsa);
    return encrypted;

}

Where modulus and exponent are NSData objects.

This works just fine, apart from all the RSA methods make the compiler whine at me about how they're deprecated on Mac OS 10.7.

Is there a more modern way I should be doing this? I've been Googling for a few hours and could only find iOS stuff which isn't available on the Mac (SecKeyEncrypt, etc).

To be absolutely clear, I'm not looking for an iOS solution, I'm looking for a Mac OS one.

Upvotes: 5

Views: 3153

Answers (3)

Madhuri
Madhuri

Reputation: 178

You can check this out if it helps

https://github.com/skomik/RSAUtility

Upvotes: 0

user149341
user149341

Reputation:

Per the Next-Generation Cryptographic Services presentation at WWDC 2011, OpenSSL is deprecated in Mac OS X 10.7 and later, as versioning for the OpenSSL libraries is horrific.

That being said, there's currently no direct replacement for the RSA functions in OpenSSL. Yet. You can probably continue using them for now; you'll just have to live with the warnings. Alternatively, you can take the advice given by Jon Callas in that presentation and bundle your own copy of libcrypto for RSA.

Upvotes: 6

Digitalis
Digitalis

Reputation: 570

Have you already reviewed this? It seems the exact problem your asking, however, this questions seems to be solved.

Upvotes: 1

Related Questions