Coder Social home page Coder Social logo

rsa-objc's Introduction

RSA for Objective-C

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

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

Credit

License

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

rsa-objc's People

Contributors

jslim89 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.