Skip to content
forked from jslim89/RSA-objc

Example for RSA encryption & decryption on iOS

Notifications You must be signed in to change notification settings

st400/RSA-Example

 
 

Repository files navigation

About

This example is to perform RSA encryption & decryption in iOS (Objective-C). I wrote a blog about encryption and decryption. Now I create this example is improvement on that (In my blog post: Encryption is done totally in Objective-C; Decryption cannot support chunks decryption but written in C), This example shows both encryption & decryption in C and support for longer string.

Setup

1. Download openssl library

The library can be found here

2. Include library to project

Just drag the library (with include & lib folders only) to the project. Go to project targets -> Build Settings:

  • Look for Header Search Paths, add "${SRCROOT}/Libraries/openssl/include" for example
  • Look for Library Search Paths, add "${SRCROOT}/Libraries/openssl/lib" for example

Generate Key pair

Generate private key

$ openssl genrsa -out private_key.pem 512

Generate public key from private key

$ openssl rsa -in private_key.pem -pubout -out public_key.pem

How to use

Include RSA

#include "RSA.h"

Get the path of your private key (make sure is in **Copy Bundle Resources)

![alt text] (https://raw.github.com/jslim89/RSA-Example/master/screenshots/resource_bundle.png "Copy Bundle Resources")

NSString *privateKeyPath = [[NSBundle mainBundle] pathForResource:@"private_key" ofType:@"pem"];

Decrypt using the function js_private_decrypt

char *plainText = js_private_decrypt([cipher UTF8String], [privateKeyPath UTF8String]);

// convert to NSString form
NSString *result = [NSString stringWithUTF8String:plainText];
NSLog(@"Plain text: %@", result);

(NOTE: Encryption did the same way)

Credit

About

Example for RSA encryption & decryption on iOS

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published