forked from TakeScoop/SwiftyRSA
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 9141a1b
Showing
13 changed files
with
906 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
Oops, something went wrong.