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.
attention: 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.
Available in Mac OS X v10.7. Available in iOS v7.0.
- (instancetype)initWithUserDefaults:(NSUserDefaults *)userDefaults NS_DESIGNATED_INITIALIZER;
VPNUStorage
instance which uses a custom NSUserDefaults
object.NSUserDefaults
object.This method is a convenience constructor.
attention: 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;
Available in Mac OS X v10.7. Available in iOS v7.0.
- (id)readObjectForKey:(NSString *)key forAccount:(VPNUAccountUserInfo *)account;
Available in Mac OS X v10.7. Available in iOS v7.0.
- (id)readWithDecryptionObjectForKey:(NSString *)key;
This method generates an exception if no encryption key was provided using setEncryptionKey
: method.
Available in Mac OS X v10.7. Available in iOS v7.0.
- (id)readWithDecryptionObjectForKey:(NSString *)key forAccount:(VPNUAccountUserInfo *)account;
This method generates an exception if no encryption key was provided using setEncryptionKey
: method.
Available in Mac OS X v10.7. Available in iOS v7.0.
- (void)setEncryptionKey:(NSString *)key;
The provided string is later used internally when the methods with pattern storeWithEncryptionObject
: 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.
attention: Set the key only once before making any calls to the instance. Otherwise the correctness of encryption and decryption is not guaranteed.
attention: 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.
Available in Mac OS X v10.7. Available in iOS v7.0.
- (void)storeObject:(id)object forKey:(NSString *)key;
The object parameter can be only property list objects: NSData, NSString, NSNumber, NSDate, NSArray, or NSDictionary.
Available in Mac OS X v10.7. Available in iOS v7.0.
- (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.
Available in Mac OS X v10.7. Available in iOS v7.0.
- (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.
Available in Mac OS X v10.7. Available in iOS v7.0.
- (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.
Available in Mac OS X v10.7. Available in iOS v7.0.