ios9ios keychainn失效了么

查看: 6358|回复: 9
精华0在线时间9 小时帖子主题UID191599积分118技术分60 资源分1 分享激情40 博客好友记录相册
实习工程师
县吏, 积分 118, 距离下一级还需 382 积分
UID191599积分118
一个程序,在登陆的时候会将用户名密码保存到keyChain中去。
在登陆状态下这个app被删除了,如何清除keyChain中的信息?
精华5在线时间96 小时帖子主题UID266积分47481技术分33703 资源分1030 分享激情2070 博客好友记录相册
高级架构师
UID266积分47481
删除app时,app处于非激活状态,没法代码清除
精华13在线时间8 小时帖子主题UID747积分18236技术分10223 资源分1024 分享激情244 博客好友记录相册
UID747积分18236
这好像真捕获不了。
精华3在线时间5948 小时帖子主题UID666积分237358技术分138707 资源分5333 分享激情49919 博客好友记录相册
首席研究员
UID666积分237358
keychain是一个安全、经过加密保护的容器,用于保存密码和其它秘密信息。应用程序的keychain数据存储在应用程序沙箱之外。如果应用程序被卸载,则该数据会自动被删除。
小飞飞快飞
精华3在线时间5948 小时帖子主题UID666积分237358技术分138707 资源分5333 分享激情49919 博客好友记录相册
首席研究员
UID666积分237358
上面的apple的原话,意思应该是用不着自己清除。
小飞飞快飞
精华0在线时间9 小时帖子主题UID191599积分118技术分60 资源分1 分享激情40 博客好友记录相册
实习工程师
县吏, 积分 118, 距离下一级还需 382 积分
UID191599积分118
Flying 发表于
keychain是一个安全、经过加密保护的容器,用于保存密码和其它秘密信息。应用程序的keychain数据存储在应用 ...
不会被自动清除的 貌似ios3以后就会一直存在
在模拟器上我也试过了,是不会被清除的
现在就是不想删除app后,再次安装keyChain里面还有数据。。。
PS:这边比CocoaChina热心多了,Thanks!
精华0在线时间9 小时帖子主题UID191599积分118技术分60 资源分1 分享激情40 博客好友记录相册
实习工程师
县吏, 积分 118, 距离下一级还需 382 积分
UID191599积分118
Flying 发表于
keychain是一个安全、经过加密保护的容器,用于保存密码和其它秘密信息。应用程序的keychain数据存储在应用 ...
貌似3.0以后keChain不会被自动清除,下次再安装,这个依然存在
模拟器上试过了,keyChain的内容依然存在,估计得恢复出厂设置才行
难道就没办法自己清除了? 真悲催。。。
精华1在线时间68 小时帖子主题UID187794积分2020技术分1360 资源分25 分享激情345 博客好友记录相册
知县, 积分 2020, 距离下一级还需 2980 积分
UID187794积分2020
yueratdiv 发表于
貌似3.0以后keChain不会被自动清除,下次再安装,这个依然存在
模拟器上试过了,keyChain的内容依然存在 ...
大不了安装的时候先把以前的keychain给删除掉呗。
精华0在线时间9 小时帖子主题UID191599积分118技术分60 资源分1 分享激情40 博客好友记录相册
实习工程师
县吏, 积分 118, 距离下一级还需 382 积分
UID191599积分118
kyelup 发表于
大不了安装的时候先把以前的keychain给删除掉呗。
好嘛。。。
虽然有点坑爹,但貌似暂时就只有这种方法了。。。
精华0在线时间0 小时帖子主题UID365680积分21技术分15 资源分1 分享激情0 博客好友记录相册
乡绅, 积分 21, 距离下一级还需 79 积分
UID365680积分21
keychain里面的信息是跟随设备的,存储在Device/var/keychains/路径下是一个数据库文件,里面的内容已经被加密过了,只有手动删除,或者系统还原才会被清理掉,越狱环境下可以自己写sql语句清除,另外登录信息建议写在default里面,写在keychain里面对用户来说,账户的安全就不好保障
一级王者勋章
一级王者勋章
二级精英勋章
二级精英勋章
三级英豪勋章
三级英豪勋章
四级英才勋章
四级英才勋章
DEVDIV博主
DEVDIV人才
十级贡献勋章
十级贡献勋章
九级光辉勋章
九级光辉勋章
及时将最新信息发给我
通过Email及时将最新的模板和服务发给我。
及时了解我们最新动态。关注我们的微博
官方微博: &&&iOS开发——keychain的使用 - 博客频道 - CSDN.NET
念茜的博客
我是一单线程妞儿
分类:【iOS 应用程序开发】
通常情况下,我们用NSUserDefaults存储数据信息,但是对于一些私密信息,比如密码、证书等等,就需要使用更为安全的keychain了。keychain里保存的信息不会因App被删除而丢失,在用户重新安装App后依然有效,数据还在。使用苹果官方发布的KeychainItemWrapper或者SFHFKeychainUtils很方便,后来看到&一文,觉得对了解keychain有很大的帮助,于是ARC控也尝试了一把。需要导入Security.framework&@implementation WQKeyChain
+ (NSMutableDictionary *)getKeychainQuery:(NSString *)service {
return [NSMutableDictionary dictionaryWithObjectsAndKeys:
(__bridge_transfer id)kSecClassGenericPassword,(__bridge_transfer id)kSecClass,
service, (__bridge_transfer id)kSecAttrService,
service, (__bridge_transfer id)kSecAttrAccount,
(__bridge_transfer id)kSecAttrAccessibleAfterFirstUnlock,(__bridge_transfer id)kSecAttrAccessible,
+ (void)save:(NSString *)service data:(id)data {
//Get search dictionary
NSMutableDictionary *keychainQuery = [self getKeychainQuery:service];
//Delete old item before add new item
SecItemDelete((__bridge_retained CFDictionaryRef)keychainQuery);
//Add new object to search dictionary(Attention:the data format)
[keychainQuery setObject:[NSKeyedArchiver archivedDataWithRootObject:data] forKey:(__bridge_transfer id)kSecValueData];
//Add item to keychain with the search dictionary
SecItemAdd((__bridge_retained CFDictionaryRef)keychainQuery, NULL);
+ (id)load:(NSString *)service {
NSMutableDictionary *keychainQuery = [self getKeychainQuery:service];
//Configure the search setting
[keychainQuery setObject:(id)kCFBooleanTrue forKey:(__bridge_transfer id)kSecReturnData];
[keychainQuery setObject:(__bridge_transfer id)kSecMatchLimitOne forKey:(__bridge_transfer id)kSecMatchLimit];
CFDataRef keyData = NULL;
if (SecItemCopyMatching((__bridge_retained CFDictionaryRef)keychainQuery, (CFTypeRef *)&keyData) == noErr) {
ret = [NSKeyedUnarchiver unarchiveObjectWithData:(__bridge_transfer NSData *)keyData];
} @catch (NSException *e) {
NSLog(@&Unarchive of %@ failed: %@&, service, e);
} @finally {
+ (void)delete:(NSString *)service {
NSMutableDictionary *keychainQuery = [self getKeychainQuery:service];
SecItemDelete((__bridge_retained CFDictionaryRef)keychainQuery);
比如,保存密码@interface WQUserDataManager : NSObject
* @brief 存储密码
+(void)savePassWord:(NSString *)
* @brief 读取密码
* @return 密码内容
+(id)readPassW
* @brief 删除密码数据
+(void)deletePassW
#import &WQUserDataManager.h&
@implementation WQUserDataManager
static NSString * const KEY_IN_KEYCHAIN = @&com.wuqian.app.allinfo&;
static NSString * const KEY_PASSWORD = @&com.wuqian.app.password&;
+(void)savePassWord:(NSString *)password
NSMutableDictionary *usernamepasswordKVPairs = [NSMutableDictionary dictionary];
[usernamepasswordKVPairs setObject:password forKey:KEY_PASSWORD];
[WQKeyChain save:KEY_IN_KEYCHAIN data:usernamepasswordKVPairs];
+(id)readPassWord
NSMutableDictionary *usernamepasswordKVPair = (NSMutableDictionary *)[WQKeyChain load:KEY_IN_KEYCHAIN];
return [usernamepasswordKVPair objectForKey:KEY_PASSWORD];
+(void)deletePassWord
[WQKeyChain delete:KEY_IN_KEYCHAIN];
实现一个简单的界面,把设定的密码存起来,然后立即读取显示出来看看效果-(IBAction)btnAciton:(id)sender
[WQUserDataManager savePassWord:self.textfield.text];
self.label.text = [WQUserDataManager readPassWord];
}达到了预期的效果。
yiyaaixuexi
排名:第168名
本博客中所有原创文章及译文均采用进行许可
(3)(9)(26)(71)(3)(26)(2)(6)下次自动登录
关注移动互联网和移动APP开发工具、开发框架、测试工具、微信开发、Android源码、Android开源类库以及各种开源组件的IT科技网站
现在的位置:
iOS开发——如何使用keyChain获取苹果设备唯一标识符
本文主要讲述了如何使用keyChain获取苹果设备的唯一标识符UUID,以及在获取UUID时遇到的困难和解决方案。现在整理出来分享给iOS程序员兄弟们,希望给他们的开发工作带来帮助。
最近在研究实现获取设备唯一标识符时,经过各方面调研,发现使用苹果官方推荐的keyChain还是挺不错的。
Apple提供了一个叫GenericKeychain的例子程序,在这里:/library/ios/#samplecode/GenericKeychain/Listings/Classes_KeychainItemWrapper_h.html#//apple_ref/doc/uid/DTS-Classes_KeychainItemWrapper_h-DontLinkElementID_9,其中封装了一个简化Keychain操作的类:KeychainItemWrapper,可以拿来直接使用,记得加入Security.framework!吐槽下。苹果demo也有内存泄漏,而且没有适配arc,所以有警告记得在Build Phases 的.m文件后加上-fno-objc-arc.
然后在Capabilities里打开keyChain Sharing ,新版本Xcode会自动生成一个name.entitlements文件,旧版本就需要自己在工程目录下新建一个KeychainAccessGroups.plist文件,该文件的结构中最顶层的节点必须是一个名为“keychain-access-groups”的Array,并且该Array中每一项都是一个描述分组的NSString。对于String的格式也有相应要求,格式为:.xxxx.name,其中APPIdentifier就是你的开发者帐号对应的ID。
其中AppIdentifier 这个新版本xcode要去钥匙串里去找。1.打开钥匙串 2.选择我的证书 3.看自己使用的证书名字后面有个(xxxxxx)这十个大写字母就是我们要找的东西。
这个写错了是有要报错的。
下面在一个公共类里加上
+(NSString *)getUUID
KeychainItemWrapper *keychainItem = [[KeychainItemWrapper alloc]
initWithIdentifier:@UUID
accessGroup:@.yjxh.pengsi];//YOUR_BUNDLE_SEED.
NSString *strUUID = [keychainItem objectForKey:(id)CFBridgingRelease(kSecValueData)];
//首次执行该方法时,uuid为空
if ([strUUID isEqualToString:@])
CFUUIDRef uuidRef = CFUUreate(kCFAllocatorDefault);
strUUID = (NSString *)CFBridgingRelease(CFUUIDCreateString (kCFAllocatorDefault,uuidRef));
[keychainItem setObject:strUUID forKey:(id)CFBridgingRelease(kSecValueData)];
return strUUID;
【上篇】【下篇】iOS Keychain SecItemAdd returns -25243 - Stack Overflow
to customize your list.
Announcing Stack Overflow Documentation
We started with Q&A. Technical documentation is next, and we need your help.
Whether you're a beginner or an experienced developer, you can contribute.
I'm working on updating an
with a minor change in its default configuration. It's been awhile since I've built it last, though, and so I've upgraded Xcode to 4.2 and included iOS 5 support in the latest builds.
When I go to test on the device, I get the following assertion error:
20:57:18.869 RoseBandwidth[903:707] Tried to add item, got result: -25243
20:57:18.870 RoseBandwidth[903:707] *** Assertion failure in -[KeychainItemWrapper writeToKeychain], /Users/tim/code/RoseBandwidth/Classes/KeychainItemWrapper.m:312
20:57:18.872 RoseBandwidth[903:707] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Couldn't add the Keychain Item.'
I'm using the implementation of the KeychainItemWrapper class from Apple's . It's worth noting that this error only shows up on the device, not in the Simulator (and I'm aware of the access group restriction differences between platforms, but usually I thought that caused problems on the Simulator, not actual hardware).
Why would I be getting this error back? I've touched nothing relevant to the keychain-rela it stores and retrieves data exactly like it used to.
44.4k16121141
Okay, I couldn't quite get your project to build, but from
I think you might want to check your entitlements file. At least in the github project you didn't have anything specified in the Keychain Access Groups.
For future searchers who happen to end up here, another possible cause of the -25243 error (which means No access control, BTW) is running on the simulator.
My best theory is the app's provisioning profile (or the signature thereof) is how the app knows what its bundle seed is. And the bundle seed needs to be part of the your keychain's access group name. But apps run on the simulator don't get signed, and so have a missing (or different?) bundle seed than you specified keychain-access-group.
Or something. It's all so poorly documented, it's hard to tell what's what. Just try running it on a device and see if that helps.
12.1k44175
I get the same error from time to time in the simulator even if I did not touch the code. A reset of the simulator solves the problem for me.
See this question/answer how to reset the simulator:
As others have pointed out, in device builds error -25243 is often caused by trying to access a keychain access group that you don't have permissions for.
(It's missing from your Entitlements.plist file or your provisioning profile.)
But in the simulator there can be another cause.
The simulator doesn't support keychain access groups at all, so if you set the kSecAttrAccessGroup property on a keychain item and try to write it you'll get this -25243 error code.
FYI, Apple's
sample code has this comment:
// Ignore the access group if running on the iPhone simulator.
// Apps that are built for the simulator aren't signed, so there's no keychain access group
// for the simulator to check. This means that all apps can see all keychain items when run
// on the simulator.
// If a SecItem contains an access group attribute, SecItemAdd and SecItemUpdate on the
// simulator will return -25243 (errSecNoAccessForItem).
3,74112429
For those of you getting this error and trying to achieve "Shared Key Chain Access" between two apps:
You need to create an App Id for your app with same Team Id you selected when you first activated "Shared Keychain Access" in 'Capabilities'. Create your App Id in here:
After that you need to create provisioning profile from that App Id and download it to your computer.(Double click it to install to x-code)
I assume you already know you need "App ID Prefix" to access key chain, but for those who don't know:
"App ID Prefix" is unique text identifier associated with your Apple developer account:
To access "SharedKeychain" you need to implement it like this before you try to write or read from keychain
keychainAccessGroupName = "AB123CDE45.myKeyChainGroup":
You can check out this tutorial for further info:
Hope that helps.
Your Answer
Sign up or
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Post as a guest
By posting your answer, you agree to the
Not the answer you're looking for?
Browse other questions tagged
The week's top questions and answers
Important community announcements
Questions that need answers
By subscribing, you agree to the
Stack Overflow works best with JavaScript enabled不知不觉已到八月中旬,青涩的那年也即将踏入大学校园面对来自五湖四海的好基友。每周...
或许有一天,你会感受到Apple Pay不知不觉就在你身边,无处不在。
短时间国内还很难实现如同美国、日本那样的游戏分级制度,目前至少需要解决两个问题.....
无论苹果选择哪一种摄像头技术,我们都知道iPhone 7 Plus在拍照体验上要更加优越。
这位CEO每一次访华都是干大事了,这一次也许和iPhone 7首发相关。
又一场世纪审判!现在FTC应该正在密切关注苹果在音乐行业的动态。
能获得同行的赞赏和承认怎么看都是一件好事~
在苹果的内部,或许正在执行三年一更的节奏。
游戏采用了横版卡通风格的画面设计,整体感觉制作还是非常精致的,而且游戏中普遍采用...
玩家所要做的就是需要根据游戏所提供的立体图形让自己能够从起点到达终点。
虽然如今人们的生活还算的上是安定和平的,虽说偶有冲突,但是总体上来说每天都过的还...
《石头阅读》这款专注移动阅读的 APP 为我们提供了极大的阅读便利,从界面、功能、阅...
之前曾推出过《战锤40K:太空野狼》的 HeroCraft 近日又给我们带来了一款新作品《僵尸...
一早便有消息传出,知名游戏开发商 Crescent Moon 将会在今年8月份推出一款全新的冒险...
在沉寂了一段时间之后,加菲猫又出现在我们的视野之中,在《加菲猫:我的节食减肥计划...
对于经常丢三落四的用户来说,通过虚拟助手 Alexa 控制 TrackR 应用能够很快找到 iPho...
既然取名“机甲”,那么机身的外观设计就一定会带有高达上的科技风格...
其实你也可以选择一边手戴一个,只不过这样......
新耳机共有两款,都不是苹果自己做的,而是来自第三方品牌Audeze,型号分别为“EL-8 T...
给 Apple Watch 提供续航并没有想象中那么容易,因为他们需要将苹果提供的官方充电器...
面对着很可能将要和耳机插孔说再见的未来,果粉们的心中总是夹杂着期待和忐忑不安。我...
如果你想给自己的 iPhone 添加一些更加灵活的使用方式的话,Spigen Universal 金属支...
嗯,看起来有点滑稽,你要不要试试?
【急】ios8.1不小心手贱删了keychain-2.db之后怎么还原都不行,WIFI全部密码错误
注册时间 最后登录
在线时间2 小时 UID
主题帖子人气
小苹果, 积分 19, 距离下一级还需 31 积分
RT,包括还原所有设置和网络设置,急了一个下午了哭死。
注册时间 最后登录
在线时间602 小时 UID
主题帖子人气
里面全删 重启激活
威锋旗下产品
Hi~我是威威!
沪公网安备 29号 | 沪ICP备号-1
新三板上市公司威锋科技(836555)
增值电信业务经营许可证:
Powered by Discuz!

我要回帖

更多关于 ios开发keychain 的文章

 

随机推荐