GithubHelp home page GithubHelp logo

isabella232 / sqlciphermanager Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sqlcipher/sqlciphermanager

0.0 0.0 0.0 325 KB

SQLCipher access manager class, and a Cocoa project for building a static library

Home Page: http://www.zetetic.net

Objective-C 100.00%

sqlciphermanager's Introduction

== SQLCipher Manager ==

SQLCipher is an SQLite extension that provides transparent 256 bit AES encryption of database files.
http://github.com/sjlombardo/sqlcipher

SQLCipherManager is a class implementing a singleton object for accessing the database connection. Sounds fairly unnecessary until you consider that SQLCipher databases are protected by a key, the databases can be re-keyed, there are optional settings for key-derivation and AES cipher modes, and it's the kind of code you'd want to re-use in multiple programs.

Questions about this code can be posted to the SQLCipher-Users Google Group:
http://groups.google.com/group/sqlcipher

Please use the Github Issues tracker to report bugs and make enhancement requests or, better yet, fork the code and send pull requests / patches.

Discussion:

We needed a singleton object/class for our iPhone application using SQLCipher, and this implements a delegate protocol they can use to respond to interesting events. An application might be wired create an application-specific schema once the database is created, or it might be configured to check the schema version after the database is opened and do a migration if it's out of date.

Usage example from the application delegate of our iPhone application Strip:

    - (void)applicationDidFinishLaunching:(UIApplication *)application {
    	NSLog(@"Setting up sqlcipher manager, and ourself as delegate...");
    	// setup the db manager register as the delegate
    	SQLCipherManager *dm = [SQLCipherManager sharedManager];
    	[dm setDelegate:self];
    	// set the databasePath property (required), use default iphone app documents directory
    	NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    	NSString *saveDirectory = [paths objectAtIndex:0];
    	NSString *databasePath = [saveDirectory stringByAppendingPathComponent:CONFIG_DBNAME];
    	NSLog(@"setting db path to %@", databasePath);
    	[dm setDatabasePath:databasePath];

    	[self launchLoginView];
    }

    # pragma mark -
    # pragma mark SQLCipherManagerDelegate

    - (void)didOpenDatabase {
    	NSLog(@"Database opened");
    	SQLCipherManager *dm = [SQLCipherManager sharedManager];
    	NSUInteger schemaVersion = [dm getSchemaVersion];
    	if (schemaVersion != CONFIG_SCHEMAVERSION) {
    		NSLog(@"handing off to schema manager, found old version %d", schemaVersion);
    		StripSchemaManager *schemaManager = [[StripSchemaManager alloc] initWithSQLCipherManager:dm];
    		[schemaManager migrate:CONFIG_SCHEMAVERSION];
    		[schemaManager release];
    	}
    }

    - (void)didCreateDatabase {
    	NSLog(@"Database created, migrating");
    	SQLCipherManager *dm = [SQLCipherManager sharedManager];
    	StripSchemaManager *schemaManager = [[StripSchemaManager alloc] initWithSQLCipherManager:dm];
    	[schemaManager migrate:CONFIG_SCHEMAVERSION];
    }

    - (void)didEncounterDatabaseError:(NSString *)error {
    	NSLog(@"Database error! %@", error);
    	SQLCipherManager *dm = [SQLCipherManager sharedManager];
    	[dm closeDatabase];
    	abort(); // ouch, yo, but it leaves us a crash log for later
    }

    - (void)didEncounterRekeyError {
    	[self lockApplication];
    	[self presentError:[NSError errorUsingDatabase:@"An error occured rekeying the database. Please login again using your original password" reason:@""]];
    }

Use of this software is governed by an MIT-style license.

[License]

Copyright (c) 2010, ZETETIC LLC
All rights reserved.
http://www.zetetic.net

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
    * Redistributions of source code must retain the above copyright
      notice, this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright
      notice, this list of conditions and the following disclaimer in the
      documentation and/or other materials provided with the distribution.
    * Neither the name of the ZETETIC LLC nor the
      names of its contributors may be used to endorse or promote products
      derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY ZETETIC LLC ''AS IS'' AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL ZETETIC LLC BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

sqlciphermanager's People

Contributors

billymeltdown avatar developernotes avatar r4n avatar sjlombardo 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.