# RNCryptor
[](https://dashboard.buddybuild.com/apps/57ea731dbd45750100873fb1/build/latest)
Cross-language AES Encryptor/Decryptor [data format](https://github.com/RNCryptor/RNCryptor-Spec/blob/master/RNCryptor-Spec-v3.md).
The primary targets are Swift and Objective-C, but implementations are available in [C](https://github.com/RNCryptor/RNCryptor-C), [C++](https://github.com/RNCryptor/RNCryptor-cpp), [C#](https://github.com/RNCryptor/RNCryptor-cs), [Erlang](https://github.com/RNCryptor/RNCryptor-erlang), [Go](https://github.com/RNCryptor/RNCryptor-go), [Haskell](https://github.com/RNCryptor/rncryptor-hs), [Java](https://github.com/RNCryptor/JNCryptor),
[PHP](https://github.com/RNCryptor/RNCryptor-php), [Python](https://github.com/RNCryptor/RNCryptor-python),
[Javascript](https://github.com/chesstrian/JSCryptor), and [Ruby](https://github.com/RNCryptor/ruby_rncryptor).
The data format includes all the metadata required to securely implement AES encryption, as described in ["Properly encrypting with AES with CommonCrypto,"](http://robnapier.net/aes-commoncrypto) and [*iOS 6 Programming Pushing the Limits*](http://iosptl.com), Chapter 15. Specifically, it includes:
* AES-256 encryption
* CBC mode
* Password stretching with PBKDF2
* Password salting
* Random IV
* Encrypt-then-hash HMAC
## Contents
* [Format Versus Implementation](#format-versus-implementation)
* [Basic Password Usage](#basic-password-usage)
* [Incremental Usage](#incremental-usage)
* [Installation](#installation)
* [Advanced Usage](#advanced-usage)
* [FAQ](#faq)
* [Design Considerations](#design-considerations)
* [License](#license)
## Format Versus Implementation
The RNCryptor data format is cross-platform and there are many implementations. The framework named "RNCryptor" is a specific implementation for Swift and Objective-C. Both have version numbers. The current data format is v3. The current framework implementation (which reads the v3 format) is v4.
## Basic Password Usage
```swift
// Encryption
let data: NSData = ...
let password = "Secret password"
let ciphertext = RNCryptor.encrypt(data: data, withPassword: password)
// Decryption
do {
let originalData = try RNCryptor.decrypt(data: ciphertext, withPassword: password)
// ...
} catch {
print(error)
}
```
## Incremental Usage
RNCryptor supports incremental use, for example when using with `NSURLSession`. This is also useful for cases where the encrypted or decrypted data will not comfortably fit in memory.
To operate in incremental mode, you create an `Encryptor` or `Decryptor`, call `updateWithData()` repeatedly, gathering its results, and then call `finalData()` and gather its result.
```swift
//
// Encryption
//
let password = "Secret password"
let encryptor = RNCryptor.Encryptor(password: password)
let ciphertext = NSMutableData()
// ... Each time data comes in, update the encryptor and accumulate some ciphertext ...
ciphertext.appendData(encryptor.updateWithData(data))
// ... When data is done, finish up ...
ciphertext.appendData(encryptor.finalData())
//
// Decryption
//
let password = "Secret password"
let decryptor = RNCryptor.Decryptor(password: password)
let plaintext = NSMutableData()
// ... Each time data comes in, update the decryptor and accumulate some plaintext ...
try plaintext.appendData(decryptor.updateWithData(data))
// ... When data is done, finish up ...
try plaintext.appendData(decryptor.finalData())
```
### Importing into Swift
Most RNCryptor symbols are nested inside an `RNCryptor` namespace.
## Installation
### Requirements
RNCryptor 5 is written in Swift 3 and does not bridge to Objective-C (it includes features that are not available). If you want an ObjC implementation, see [RNCryptor-objc](https://github.com/RNCryptor/RNCryptor-objc). That version can be accessed from Swift, or both versions can coexist in the same project.
### The Bridging Header
CommonCrypto is not a modular header (and Apple has suggested it may never be). This makes it very challenging to import into Swift. To work around this, the necessary header files have been copied into `RNCryptor.h`, which needs to be bridged into Swift. You can do this either by using RNCryptor as a framework, adding `#import "RNCryptor/RNCryptor.h"` to your existing bridging header, or making `RNCryptor/RNCryptor.h` your bridging header in Build Settings, "Objective-C Bridging Header."
### Installing Manually
The easiest way to use RNCryptor is by making it part of your project, without a framework. RNCryptor is just one swift file and one bridging header, and you can skip all the complexity of managing frameworks this way. It also makes version control very simple if you use submodules, or checkin specific versions of RNCryptor to your repository.
This process works for most targets: iOS and OS X GUI apps, Swift frameworks, and OS X commandline apps. **It is not safe for ObjC frameworks or frameworks that may be imported into ObjC, since it would cause duplicate symbols if some other framework includes RNCryptor.**
* Drag and link `RNCryptor/RNCryptor.swift` and `RNCryptor.h` into your project
* If you already have a bridging header file, add `#import "RNCryptor.h"` (or the path to which you copied `RNCryptor.h`).
* If you don't have a bridging header:
* Swift project: In your target's Build Settings, set "Objective-C Bridging Header" to your path for `RNCryptor.h`. (Or create a bridiging header and follow instructions above.)
* ObjC project: Xcode will ask if you want to create a bridging header. Allow it to, and add `#import "RNCryptor.h"` to the header (or the path to which you copied `RNCryptor.h`)
* To access RNCryptor from Swift, you don't need to import anything. It's just part of your module.
* To access RNCryptor from ObjC, import your Swift header (*modulename*-Swift.h). For example: `#import "MyApp-Swift.h"`.
Built this way, you don't need to (and can't) `import RNCryptor` into your code. RNCryptor will be part of your module.
### [Carthage](https://github.com/Carthage/Carthage)
github "RNCryptor/RNCryptor" ~> 5.0
This approach will not work for OS X commandline apps. Don't forget to embed `RNCryptor.framework`.
Built this way, you should add `@import RNCryptor;` to your ObjC or `import RNCryptor` to your Swift code.
This approach will not work for OS X commandline apps.
### [CocoaPods](https://cocoapods.org)
pod 'RNCryptor', '~> 5.0'
This approach will not work for OS X commandline apps.
Built this way, you should add `import RNCryptor` to your Swift code.
## Advanced Usage
### Version-Specific Cryptors
The default `RNCryptor.Encryptor` is the "current" version of the data format (currently v3). If you're interoperating with other implementations, you may need to choose a specific format for compatibility.
To create a version-locked cryptor, use `RNCryptor.EncryptorV3` and `RNCryptor.DecryptorV3`.
Remember: the version specified here is the *format* version, not the implementation version. The v4 RNCryptor framework reads and writes the v3 RNCryptor data format.
### Key-Based Encryption
*You need a little expertise to use key-based encryption correctly, and it is very easy to make insecure systems that look secure. The most important rule is that keys must be random across all their bytes. If you're not comfortable with basic cryptographic concepts like AES-CBC, IV, and HMAC, you probably should avoid using key-based encryption.*
Cryptography works with keys, which are random byte sequences of a specific length. The RNCryptor v3 format uses two 256-bit (32-byte) keys to perform encryption and authentication.
Passwords are not "random byte sequences of a specific length." They're not random at all, and they can be a wide variety of lengths, very seldom exactly 32. RNCryptor defines a specific and secure way to convert passwords into keys, and that
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论

















收起资源包目录





































































































共 3985 条
- 1
- 2
- 3
- 4
- 5
- 6
- 40
资源评论

csdnUser2017
- 粉丝: 22
- 资源: 37

上传资源 快速赚钱
我的内容管理 收起
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助

会员权益专享
最新资源
- 【计算机毕业设计】javaEE+SqlServer企业车辆管理系统设计与实现
- Linux网络操作系统-课程标准
- 操作系统课程设计高分大作业(97分),共25页word版本
- 全过程注册openAPI详细步骤
- 【计算机毕业设计】基于javaEE+Servlet+MySql的银行柜员业务绩效考核系统的设计与实现
- Android-iEnergyCharge20230327001.apk.1.1
- 【计算机毕业设计】基于java+spring+mysql的新闻发布及管理系统
- 基于STM32f103的电子秤系统,资源主要有硬件相关资料,软件程序,全篇论文;可用于毕业设计,单片机,嵌入式,传感器课程设计
- 【计算机毕业设计】企业财务管理系统设计与实现
- 基于MindSpore内置的并行技术和组件化设计
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈



安全验证
文档复制为VIP权益,开通VIP直接复制
