Coder Social home page Coder Social logo

haikieu / nsuserdefaults-sevensecuritylayers Goto Github PK

View Code? Open in Web Editor NEW
67.0 1.0 14.0 336 KB

Secure your NSUserDefaults just by one line of code. Simple usage / strong encryption protection / maximum productivity

License: MIT License

Objective-C 93.56% Ruby 1.29% C 1.17% Shell 3.97%
objective-c ios nsuserdefaults

nsuserdefaults-sevensecuritylayers's Introduction

NSUserDefaults+SevenSecurityLayers.h (Obsoleted, this is no longer maintained)

  • A category which provides an encryption layer for NSUserDefaults to securely save data .
  • Using strong AES 356-bit encryption

####Benefit:

* Secure user data just by one line of code.
* Support obfuscating your key in binary source
* Able to save data without encryption
* Enable to handle exceptional case via built-in NOTIFICATION
* Enable using standardUserDefaults as well as securedUserDefaults parallelly

Make donation for Hai Kieu's github


How to use

Note: Remember to install dependency first


In the implementation file, import NSUserDefaults+SevenSecurityLayers.h

#import "NSUserDefaults+SevenSecurityLayers.h"

Initialize a secured UserDefaults with a secret key.

//Recommend: Should put the secret key in implementation file to secure your key.
//Warning: Must specify the secret key before using or you get **Exception**

NSUserDefault *pref = [[NSUserDefault securedUserDefaults] setSecretKey:@"Your secret key"];

// >>> DONE! That's it, a secured storage has been created already for you to save any data later. <<<
//Demonstrate saving data

[pref setBool:YES forKey:@"DataIsSecured"];
[pref setString:@"AES 356-bit" forKey:@"KindOfEncryption"];
[pref setString:@"v1.2.0 available" forKey:@"ObfuscateSecretKey"];
[pref setString:@"Able to save data without encryption" forKey:@"KeepOrigin"];
...
[pref synchronize];
//Demonstrate retrieving data

bool yourBool = [pref boolForKey:@"DataIsSecured"];
NSString * yourString = [pref stringForKey:@"KindOfEncrytion"];
...

###Advanced usage

  • v1.2.0 available

  • Obfuscate your secret key

    Shouldn't use this NSString * theSecretKey = @"putYourKeyHere";

    Try this way ๐Ÿ‘‰ NSString * theSecretKey = @"".p.u.t.Y.o.u.r.K.e.y.H.e.r.e;

  • Store data without encryption

    `[pref setObject:@"yourValue" forKey:@"yourKey.nonSecured"];`
    
    Or
    
    `[pref setObject:@"yourValue" forKey:@"yourKey".nonSecured];`
    
  • Migrate data to secured storage

    `[NSUserDefaults migrate:[NSUserDefaults standardUserDefaults] to:pref clearSource:YES];`
    

Supported NOTIFICATION Events

  • NOTIFICATION_CANNOT_RETRIEVE_ENCRYPTED_DATA
  • NOTIFICATION_CANNOT_STORE_ENCRYPTED_DATA
  • NOTIFICATION_SECRET_KEY_NOT_SET
  • NOTIFICATION_STORED_DATA_HAS_BEEN_VIOLATED

Supported Encryption Types

Seven Security Layers Solution supports the following property types:

  • NSInteger
  • NSString
  • NSArray
  • string+array
  • NSDictionary
  • NSURL
  • NSData
  • BOOL
  • float
  • double

Contact

Email: [email protected]

Make donation for Hai Kieu's github

###Thanks to

MIT License

###Dependencies

###Dependencies Installation

  1. git:
$ git clone git://github.com/kelp404/CocoaSecurity.git
$ cd CocoaSecurity
$ git submodule update --init
  1. CocoadPods:
    add Podfile in your project path
platform :ios
pod 'CocoaSecurity'
$ pod install

nsuserdefaults-sevensecuritylayers's People

Contributors

haikieu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

nsuserdefaults-sevensecuritylayers's Issues

Secure keys cannot be made in Swift 3

The Clang ObjC importer in Swift 3 does a transform that breaks the recommended key generation ("".M().y().S().e().c().r().e().t().K().e().y()).

In order to automatically comply with the new API guide lines (which says that you should start any non-type with a lowercase letter), the importer transforms the functions for uppercased letters to lowercase, which conflicts with the lowercase letter functions.

Unfortunately, because of the typical length of keys put through your code, the Swift compiler spins into a deep loop and never finishes compiling.

To read more about the change, see https://github.com/apple/swift-evolution/blob/master/proposals/0005-objective-c-name-translation.md and search for Lowercase values.

Side note: Because you expose the letter functions as functions instead of properties, they become almost unreadable in Swift (any version). It seems a simple solution to change them from e.g. - (NSString *)a; to @property(readonly, copy) NSString *a;, which would make Swift read the same as ObjC.

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.