加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
SecureData.m 1.66 KB
一键复制 编辑 原始数据 按行查看 历史
Oscar 提交于 2017-01-10 10:44 . Add many tiny changes
#import "SecureData.h"
#define kServiceName @"UnitySecureData"
@implementation SecureData
@synthesize dict = dict_;
#pragma mark - Object Lifecycle
- (id)init {
if ((self = [super init])) {
[self retrieve];
}
return self;
}
- (void)dealloc {
self.dict = nil;
[super dealloc];
}
#pragma mark - Transaction Method
- (void)store {
NSMutableDictionary *secItem = [[[NSMutableDictionary alloc] init] autorelease];
[secItem setObject:(id)kSecClassGenericPassword forKey:(id)kSecClass];
[secItem setObject:kServiceName forKey:(id)kSecAttrService];
SecItemDelete((CFDictionaryRef)secItem);
[secItem setObject:[NSKeyedArchiver archivedDataWithRootObject:self.dict] forKey:(id)kSecValueData];
SecItemAdd((CFDictionaryRef)secItem, NULL);
}
- (void)retrieve {
self.dict = nil;
NSMutableDictionary *secItem = [[NSMutableDictionary alloc] init];
[secItem setObject:(id)kSecClassGenericPassword forKey:(id)kSecClass];
[secItem setObject:kServiceName forKey:(id)kSecAttrService];
[secItem setObject:(id)kCFBooleanTrue forKey:(id)kSecReturnData];
[secItem setObject:(id)kSecMatchLimitOne forKey:(id)kSecMatchLimit];
NSData *data = nil;
if (SecItemCopyMatching((CFDictionaryRef)secItem, (CFTypeRef *)&data) == errSecSuccess) {
self.dict = [NSKeyedUnarchiver unarchiveObjectWithData:data];
}
[data release];
if (!self.dict) self.dict = [NSMutableDictionary dictionary];
}
#pragma mark - Class Function
static SecureData *s_instance;
+ (SecureData *)sharedInstance {
if (s_instance == nil) {
s_instance = [[SecureData alloc] init];
}
return s_instance;
}
@end
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化