• This repository has been archived on 26/May/2021
  • Stars
    star
    108
  • Rank 313,742 (Top 7 %)
  • Language
    Objective-C
  • License
    MIT License
  • Created over 10 years ago
  • Updated about 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Example for RSA encryption & decryption on iOS

RSA for Objective-C

This is a plugin for RSA encryption & decryption in iOS (Objective-C). I wrote a blog about encryption and decryption.

Please don't use this anymore

This project dependent on ios-openssl which has been archived, and the precompiled binaries also been removed. I already long time didn't touch on iOS project, thus I will not support anymore.

Thanks

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

3. Include RSA-objc into your project

Drag the folder RSA-objc to your project.

4. 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

Drag the key(s) to your project, and make sure it appear in Copy Bundle Resources.

alt text

5. Add bridging header (only if you want to port to Swift)

Go to Project Targets -> select Build Settings, look for Objective-C Bridging Header

alt text

Make sure you set the correct path according to your file structure.

The SwiftBridgingHeader.h is included in this example

How to use

Include RSA

Objective-C

#import "JSRSA.h"

// set the public/private key
[JSRSA sharedInstance].publicKey = @"public_key.pem";
[JSRSA sharedInstance].privateKey = @"private_key.pem";

NSString *plainText = [[JSRSA sharedInstance] privateDecrypt:cipherText];
...

Swift

JSRSA.sharedInstance().privateKey = "private_key.pem"
JSRSA.sharedInstance().publicKey = "public_key.pem"

var plainText = JSRSA.sharedInstance().privateDecrypt(cipherText)

There are 4 methods here:

- (NSString *)publicEncrypt:(NSString *)plainText;
- (NSString *)privateDecrypt:(NSString *)cipherText;
- (NSString *)privateEncrypt:(NSString *)plainText;
- (NSString *)publicDecrypt:(NSString *)cipherText;

Try the demo project

To pull the openssl for iOS

$ git submodule update --init --recursive

Contributors

Credit

Donate

Click here to lend your support to: RSA-objc and make a donation at pledgie.com !

License

The RSA-objc is open-sourced software licensed under the MIT license.

More Repositories

1

js-learning-journey

To markdown all technical knowledge that I've been learn.
Shell
7
star
2

CropImageObjc-Example

An example project for my blog post. http://jslim.net/blog/2014-12-09-ios-crop-image-based-on-a-mask/
Objective-C
5
star
3

svn-export

A python script that export committed svn files (specify the author & revision) to a new directory
Python
3
star
4

happylucky

An e-commerce website selling Thai Amulet and its' accessories. This also my final year project on college
PHP
2
star
5

jVectorMap-example

Showing how to generate vector map & usage of jVectorMap
Python
2
star
6

git-export

For manual deployment, extract out the file(s) commited from a specific revision to a specific revision.
Python
2
star
7

jslim89.github.com

A technical blog about IT stuff
SCSS
2
star
8

Cocos2d-x-PhysicsEditor-demo

Demo to show how to create a custom physics body shape by using PhysicsEditor in Cocos2d-x v3
C++
2
star
9

ios7-statusbar-example

Just an example for my blog http://jslim.net/blog/2014/06/16/dealing-ios-7-uistatusbar/ showing how I deal with UIStatusBar
Objective-C
2
star
10

country-sql

A list of countries in in SQL form together with flags
1
star
11

site-scraper

Scrap web content, especially single page application
JavaScript
1
star
12

docker-config-dev

Docker config collection for local development
JavaScript
1
star
13

js-password-generator

JavaScript password generator based on https://www.nayuki.io/page/random-password-generator-javascript
JavaScript
1
star
14

helper-scripts

Personal helper scripts (shell, python, etc)
Shell
1
star
15

jslim89

Python
1
star
16

blockchain-learn

Learning progress on Blockchain related tutorial
JavaScript
1
star
17

2048-clone

A clone of 2048 game
JavaScript
1
star
18

php-number-to-words

A PHP script that convert the number to words, e.g. 1234 => one thousand and two hundred and thirty four
PHP
1
star
19

maplot-web

PHP
1
star
20

database-backup-cron

Simple script for backup database
Shell
1
star
21

tarc-cgpa-calc

A CGPA calculator for TARCollege written in Java. This is my diploma project.
Java
1
star
22

cicd-learning

CI/CD learning
PHP
1
star