Git Product home page Git Product logo

securensuserdefaults's Introduction

#SecureNSUserDefaults

NSUserDefaults category for iOS and Mac OS X with additional methods to securely save data using strong AES encryption.

NSUserDefaults is a great way to store simple data in a persistent way. However, information is stored unencrypted and can easily be read by human beings (e.g. with iExplorer). If you want particular information to be stored in a secure way, making it really hard for users to see the actual content, SecureNSUserDefaults might be what you're looking for.

##Installation I highly recommend you to use CocoaPods for installing this category.

###CocoaPods

pod 'SecureNSUserDefaults', '~> 1.0.0'

Import the header file everywhere you want to use SecureNSUserDefaults by placing te following code in the top of your file:

#import <SecureNSUserDefaults/NSUserDefaults+SecureAdditions.h>

###Manual

  1. Copy the files NSUserDefaults+SecureAdditions.h and NSUserDefaults+SecureAdditions.h into your project;
  2. Install CocoaSecurity;
  3. Import NSUserDefaults+SecureAdditions.h everywhere you need it.

##Usage

###Configure secret Before SecureNSUserDefaults can be used to get/save encrypted data, make sure to set a secret secret:

[[NSUserDefaults standardUserDefaults] setSecret:@"your_secret_goes_here"];

Never store the secret somewhere on your file system or in your user preferences but instead put it somewhere static in your code. Preferably use a salt string in combination with something device specific (such as NSUUID's UUIDString method).

###Store information Storing information is as easy as always. Prefix the normal NSUserDefaults methods with secret and your good to go. For example:

[[NSUserDefaults standardUserDefaults] setSecretObject:@"something_only_you_may_know" forKey:@"the_key"];

All available methods:

- (void)setSecretBool:(BOOL)value forKey:(NSString *)defaultName;
- (void)setSecretFloat:(float)value forKey:(NSString *)defaultName;
- (void)setSecretInteger:(NSInteger)value forKey:(NSString *)defaultName;
- (void)setSecretDouble:(double)value forKey:(NSString *)defaultName;
- (void)setSecretURL:(NSURL *)url forKey:(NSString *)defaultName;
- (void)setSecretObject:(id)value forKey:(NSString *)defaultName;

###Getting information Getting information works in the say way:

[[NSUserDefaults standardUserDefaults] secretStringForKey:@"the_key"];

All available methods:

- (BOOL)secretBoolForKey:(NSString *)defaultName;
- (NSData*)secretDataForKey:(NSString *)defaultName;
- (NSDictionary*)secretDictionaryForKey:(NSString *)defaultName;
- (float)secretFloatForKey:(NSString *)defaultName;
- (NSInteger)secretIntegerForKey:(NSString *)defaultName;
- (NSArray *)secretStringArrayForKey:(NSString *)defaultName;
- (NSString *)secretStringForKey:(NSString *)defaultName;
- (double)secretDoubleForKey:(NSString *)defaultName;
- (NSURL*)secretURLForKey:(NSString *)defaultName;
- (id)secretObjectForKey:(NSString *)defaultName;

Note that if the key does not exist or the data could not be decrypted, either NO, 0 or nil is returned.

##Tests The class SecureNSUserDefaultsTests contains multiple test cases. Clone the entire Xcode project and run the tests to see if everything still works.

Contact

If you have questions or suggestions, visit www.nielsmouthaan.nl and use the contact form to contact me.

Acknowledgements

License (MIT)

Copyright (c) 2013 Niels Mouthaan

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

securensuserdefaults's People

Contributors

nielsmouthaan avatar gtg465x avatar

Watchers

Peter Turza avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.