This is a plugin for RSA encryption & decryption in iOS (Objective-C). I wrote a blog about encryption and decryption.
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
The library can be found here
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
Drag the folder RSA-objc to your project.
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.
Go to Project Targets -> select Build Settings, look for Objective-C Bridging Header
Make sure you set the correct path according to your file structure.
The SwiftBridgingHeader.h is included in this example
Include RSA
#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];
...
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;
To pull the openssl for iOS
$ git submodule update --init --recursive
- jslim89 - Original author
- flexih
- mengxiangyue
The RSA-objc is open-sourced software licensed under the MIT license.