Skip to content

phimage/CryptoPrephirences

Repository files navigation

CryptoPrephirences

License Platform Language Issues Cocoapod Join the chat at https://gitter.im/phimage/Prephirences

CryptoPrephirences allows you to protect your preferences against unauthorized access and modification.

preferences["aKey", .cipher(cipher)] = "myValueToEncrypt"

It's build on top Prephirences and 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

var preferences = UserDefaults.standard
preferences["aKey", .cipher(cipher)] = value
preferences.set(value, forKey: "aKey", withCipher: cipher)

Get the decrypted value

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 :

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

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

var cryptoPreferences = MutableCryptoPrephirences(preferences: mutablePreferences, cipher: cipher)
// or for read-only CryptoPrephirences(preferences: anyPreferences, cipher: cipher)

About

Add some encryption to your sensitive preferences

Resources

License

Stars

Watchers

Forks

Packages

No packages published