https://github.com/phimage/cryptoprephirences
Add some encryption to your sensitive preferences
https://github.com/phimage/cryptoprephirences
Last synced: 8 months ago
JSON representation
Add some encryption to your sensitive preferences
- Host: GitHub
- URL: https://github.com/phimage/cryptoprephirences
- Owner: phimage
- License: mit
- Created: 2015-12-31T12:25:08.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2018-02-01T12:43:18.000Z (about 8 years ago)
- Last Synced: 2025-06-17T18:19:08.537Z (8 months ago)
- Language: Swift
- Size: 71.3 KB
- Stars: 11
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# CryptoPrephirences
[](http://mit-license.org)
[](https://developer.apple.com/resources/)
[](https://developer.apple.com/swift)
[](https://github.com/phimage/CryptoPrephirences/issues)
[](http://cocoadocs.org/docsets/Prephirences/)
[](https://gitter.im/phimage/Prephirences?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[
](#logo) CryptoPrephirences allows you to protect your preferences against unauthorized access and modification.
```swift
preferences["aKey", .cipher(cipher)] = "myValueToEncrypt"
```
It's build on top [Prephirences](https://github.com/phimage/Prephirences) and [CryptoSwift](https://github.com/krzyzanowskim/CryptoSwift)
## Installation
### Support CocoaPods
* Podfile
```
use_frameworks!
pod "CryptoPrephirences"
```
## Usage
To Encrypt and decrypt data, you will need a `CryptoSwift.Cipher`, see CryptoSwift documentation to create one.
### Encrypt/Decryp each key/value independently
#### Store any NSCoding object compliant
You can store one preference using
```swift
var preferences = UserDefaults.standard
preferences["aKey", .cipher(cipher)] = value
preferences.set(value, forKey: "aKey", withCipher: cipher)
```
#### Get the decrypted value
```swift
let value = preferences[key, .cipher(cipher)]
let value = preferences.object(forKey: key, withCipher: cipher)
```
### Encrypted Plist file
Using this method key and values will be encrypted.
You can read and write your preferences to an encrypted file using :
```swift
try anyPreferences.saveTo(filePath: "/path/to/file", withCipher:cipher)
try mutablePreferences.loadFrom(filePath: "/path/to/file", withCipher: cipher)
```
You can also initialize a `DictionaryPreferences` with `cipher`
```swift
let pref = try DictionaryPreferences(filePath: filePath, withCipher: cipher)
```
### Encrypted all values
You can use the `CryptoPrephirences`, which work as a proxy of another `Prephirences` and encrypt/decrypt using the given `cipher`
```swift
var cryptoPreferences = MutableCryptoPrephirences(preferences: mutablePreferences, cipher: cipher)
// or for read-only CryptoPrephirences(preferences: anyPreferences, cipher: cipher)
```