Use this class if you want to save any information which is specific for an account described by VPNUAccountUserInfo. This class also provides an interface to save data securely using methods which use encryption and decryption.
The class uses NSUserDefaults internally. If you clear the defaults associated with the intance of this class (generally standardUserDefaults), all stored values (including encrypted) will be lost.
Extends: NSObject
Declared in: VPNUStorage.h
+ (instancetype)defaultStorage;
The shared storage is created internally with standardUserDefaults instance of NSUserDefaults class. If you want to use any custom NSUserDefaults object, you can initialize your own instance of VPNUStorage using initWithUserDefaults: covinience initializer.
- (instancetype)initWithUserDefaults:(NSUserDefaults *)userDefaults NS_DESIGNATED_INITIALIZER;
This method is a convenience constructor.
Use this method only if you know what you are doing. Generally you want to use standardUserDefaults instance of NSUserDefaults class - simply use the defaultStorage class method (the latter is generally preferred).
- (id)readObjectForKey:(NSString *)key;
- (id)readObjectForKey:(NSString *)key forAccount:(VPNUAccountUserInfo *)account;
- (id)readWithDecryptionObjectForKey:(NSString *)key;
This method generates an exception if no encryption key was provided using setEncryptionKey: method.
- (id)readWithDecryptionObjectForKey:(NSString *)key forAccount:(VPNUAccountUserInfo *)account;
This method generates an exception if no encryption key was provided using setEncryptionKey: method.
- (void)setEncryptionKey:(NSString *)key;
The provided string is later used internally when the methods with pattern storeWithEncryptionObject:forKey: and readWithDecryptionObjectForKey: are called. It is recommended to use an arbitrary, comparatively large and permutated string for this value. Generally you are discouraged to use a user's login or password or any meaningful string as an encryption key.
Set the key only once before making any calls to the instance. Otherwise the correctness of encryption and decryption is not guaranteed.
Encryption key should be the same between the launches of your host application. If you change the key, all previously saved values will be inaccessible until you set the key back to the previous value.
- (void)storeObject:(id)object forKey:(NSString *)key;
The object parameter can be only property list objects: NSData, NSString, NSNumber, NSDate, NSArray, or NSDictionary.
- (void)storeObject:(id)object forKey:(NSString *)key forAccount:(VPNUAccountUserInfo *)account;
The object parameter can be only property list objects: NSData, NSString, NSNumber, NSDate, NSArray, or NSDictionary.
- (void)storeWithEncryptionObject:(id)object forKey:(NSString *)key;
This method generates an exception if no encryption key was provided using setEncryptionKey: method. The object parameter can be only property list objects: NSData, NSString, NSNumber, NSDate, NSArray, or NSDictionary.
- (void)storeWithEncryptionObject:(id)object forKey:(NSString *)key forAccount:(VPNUAccountUserInfo *)account;
This method generates an exception if no encryption key was provided using setEncryptionKey: method. The object parameter can be only property list objects: NSData, NSString, NSNumber, NSDate, NSArray, or NSDictionary.