All Projects → soffes → Samkeychain

soffes / Samkeychain

Licence: mit
Simple Objective-C wrapper for the keychain that works on Mac and iOS

Programming Languages

objective c
16641 projects - #2 most used programming language
swift
15916 projects
ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to Samkeychain

Corexlsx
Excel spreadsheet (XLSX) format parser written in pure Swift
Stars: ✭ 481 (-91.07%)
Mutual labels:  tvos, watchos
Purchases Ios
In-app purchases and subscriptions made easy. iOS, MacOS, iPadOS, tvOS, and WatchOS support.
Stars: ✭ 614 (-88.61%)
Mutual labels:  tvos, watchos
Impact
Crash capturing library for Apple platforms
Stars: ✭ 395 (-92.67%)
Mutual labels:  tvos, watchos
Swiftyutils
All the reusable code that we need in each project
Stars: ✭ 490 (-90.91%)
Mutual labels:  tvos, watchos
Swiftuipager
Native Pager in SwiftUI
Stars: ✭ 430 (-92.02%)
Mutual labels:  tvos, watchos
Sentry Cocoa
The official Sentry SDK for iOS, tvOS, macOS, watchOS
Stars: ✭ 370 (-93.13%)
Mutual labels:  tvos, watchos
Efqrcode
A better way to operate QR Code in Swift, support iOS, macOS, watchOS and tvOS.
Stars: ✭ 4,121 (-23.53%)
Mutual labels:  tvos, watchos
Crypto
Swift CommonCrypto wrapper
Stars: ✭ 328 (-93.91%)
Mutual labels:  tvos, watchos
Swiftframeworktemplate
A template for new Swift iOS / macOS / tvOS / watchOS Framework project ready with travis-ci, cocoapods, Carthage, SwiftPM and a Readme file
Stars: ✭ 527 (-90.22%)
Mutual labels:  tvos, watchos
Userdefaultsstore
Why not use UserDefaults to store Codable objects 😉
Stars: ✭ 416 (-92.28%)
Mutual labels:  tvos, watchos
Xcglogger
A debug log framework for use in Swift projects. Allows you to log details to the console (and optionally a file), just like you would have with NSLog() or print(), but with additional information, such as the date, function name, filename and line number.
Stars: ✭ 3,710 (-31.16%)
Mutual labels:  tvos, watchos
Gridstack
A flexible grid layout view for SwiftUI
Stars: ✭ 474 (-91.2%)
Mutual labels:  tvos, watchos
Valet
Valet lets you securely store data in the iOS, tvOS, or macOS Keychain without knowing a thing about how the Keychain works. It’s easy. We promise.
Stars: ✭ 3,712 (-31.12%)
Mutual labels:  tvos, watchos
Xcake
🍰 Describe Xcode projects in a human readable format and (re)generate one on demand.
Stars: ✭ 549 (-89.81%)
Mutual labels:  tvos, watchos
Solarized Dark For Xcode
Solarized Dark Theme for Xcode. Compatible with all modern versions of Xcode since 2013!
Stars: ✭ 358 (-93.36%)
Mutual labels:  tvos, watchos
Json
Micro framework for easily parsing JSON in Swift with rich error messages in less than 100 lines of code
Stars: ✭ 395 (-92.67%)
Mutual labels:  tvos, watchos
Web3.swift
A pure swift Ethereum Web3 library
Stars: ✭ 295 (-94.53%)
Mutual labels:  tvos, watchos
Functionkit
A framework for functional types and operations designed to fit naturally into Swift.
Stars: ✭ 302 (-94.4%)
Mutual labels:  tvos, watchos
Waterwheel.swift
The Waterwheel Swift SDK provides classes to natively connect iOS, macOS, tvOS, and watchOS applications to Drupal 7 and 8.
Stars: ✭ 415 (-92.3%)
Mutual labels:  tvos, watchos
Stringz
A lightweight and powerful editor for localizing iOS, macOS, tvOS, and watchOS applications.
Stars: ✭ 440 (-91.84%)
Mutual labels:  tvos, watchos

SAMKeychain

Version CocoaPods Carthage compatible

SAMKeychain is a simple wrapper for accessing accounts, getting passwords, setting passwords, and deleting passwords using the system Keychain on Mac OS X and iOS.

Adding to Your Project

Simply add the following to your Podfile if you're using CocoaPods:

pod 'SAMKeychain'

or Cartfile if you're using Carthage:

github "soffes/SAMKeychain"

To manually add to your project:

  1. Add Security.framework to your target
  2. Add SAMKeychain.h, SAMKeychain.m, SAMKeychainQuery.h, and SAMKeychainQuery.m to your project.

SAMKeychain requires ARC.

Note: Currently SAMKeychain does not support Mac OS 10.6.

Working with the Keychain

SAMKeychain has the following class methods for working with the system keychain:

+ (NSArray *)allAccounts;
+ (NSArray *)accountsForService:(NSString *)serviceName;
+ (NSString *)passwordForService:(NSString *)serviceName account:(NSString *)account;
+ (BOOL)deletePasswordForService:(NSString *)serviceName account:(NSString *)account;
+ (void)setAccessibilityType:(CFTypeRef)accessibilityType;
+ (BOOL)setPassword:(NSString *)password forService:(NSString *)serviceName account:(NSString *)account;

Easy as that. (See SAMKeychain.h and SAMKeychainQuery.h for all of the methods.)

Documentation

Use prepared documentation

Read the online documentation.

Debugging

If your saving to the keychain fails, use the NSError object to handle it. You can invoke [error code] to get the numeric error code. A few values are defined in SAMKeychain.h, and the rest in SecBase.h.

NSError *error = nil;
SAMKeychainQuery *query = [[SAMKeychainQuery alloc] init];
query.service = @"MyService";
query.account = @"soffes";
[query fetch:&error];

if ([error code] == errSecItemNotFound) {
    NSLog(@"Password not found");
} else if (error != nil) {
	NSLog(@"Some other error occurred: %@", [error localizedDescription]);
}

Obviously, you should do something more sophisticated. You can just call [error localizedDescription] if all you need is the error message.

Disclaimer

Working with the keychain is pretty sucky. You should really check for errors and failures. This library doesn't make it any more stable, it just wraps up all of the annoying C APIs.

You also really should not use the default but set the accessibilityType. kSecAttrAccessibleWhenUnlocked should work for most applications. See Apple Documentation for other options.

Thanks

This was originally inspired by EMKeychain and SDKeychain (both of which are now gone). Thanks to the authors. SAMKeychain has since switched to a simpler implementation that was abstracted from SSToolkit.

A huge thanks to Caleb Davenport for leading the way on version 1.0 of SAMKeychain.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].