Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ldiqual committed Jul 3, 2015
0 parents commit 9141a1b
Show file tree
Hide file tree
Showing 13 changed files with 906 additions and 0 deletions.
43 changes: 43 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Xcode
#
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore

## Build generated
build/
DerivedData

## Various settings
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata

## Other
*.xccheckout
*.moved-aside
*.xcuserstate
*.xcscmblueprint

## Obj-C/Swift specific
*.hmap
*.ipa

# CocoaPods
#
# We recommend against adding the Pods directory to your .gitignore. However
# you should judge for yourself, the pros and cons are mentioned at:
# http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control
#
# Pods/

# Carthage
#
# Add this line if you want to avoid checking in source code from Carthage dependencies.
# Carthage/Checkouts

Carthage/Build
60 changes: 60 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
SwiftyRSA
=========

Public key RSA encryption in Swift.

Usage
-----

### Add keys ###

First of all, create an instance of `SwiftyRSA`:

```
let rsa = SwiftyRSA()
```

#### Public key (PEM) ####

```
let pubPath = bundle.pathForResource("public", ofType: "pem")!
let pubString = NSString(contentsOfFile: pubPath, encoding: NSUTF8StringEncoding, error: nil)! as String
let pubKey = rsa.publicKeyFromPEMString(pubString)!
```

#### Public key (DER) ####

```
let rsa = SwiftyRSA()
let pubPath = bundle.pathForResource("public", ofType: "der")!
let pubData = NSData(contentsOfFile: pubPath)!
let pubKey = rsa.publicKeyFromDERData(pubData)!
```

#### Private key (PEM) ####

```
let privPath = bundle.pathForResource("private", ofType: "pem")!
let privString = NSString(contentsOfFile: privPath, encoding: NSUTF8StringEncoding, error: nil)! as String
let privKey = rsa.privateKeyFromPEMString(privString)!
```

### Encrypt ###

```
let encryptedData = rsa.encryptString(str, publicKey: pubKey)!
let encryptedString = NSString(data: encrypted, encoding: NSUTF8StringEncoding)!
```

### Decrypt ###

```
let decrypted = rsa.decryptData(encrypted, privateKey: privKey)!
let encryptedString = NSString(data: encrypted, encoding: NSUTF8StringEncoding)!
```

Inspired from
-------------

- <http://blog.flirble.org/2011/01/05/rsa-public-key-openssl-ios/>
- <https://github.com/lancy/RSADemo>
Loading

0 comments on commit 9141a1b

Please sign in to comment.