在我的 MacOS 应用程序中,我存储电子邮件帐户数据,因此 5 个应用程序密码保存在钥匙串中。当应用程序启动时,Keychain 询问 5 次以始终允许... 有没有办法让 Keychain 接受我的应用程序一次?例如,Adium 存储多个帐户数据,并且在其钥匙串中只有一个条目(种类:“Internet 密码”)。
代码签名是避免这种情况的唯一方法吗?
店铺:
+(void)storePasswordKeychainWithPassAndKey:(NSString *)passwordStr:(NSString *)accountNameStr {
const char * accountName = [accountNameStr UTF8String];
const char * password = [passwordStr UTF8String];
OSStatus status;
status = SecKeychainAddGenericPassword(NULL,
strlen(serviceName), serviceName,
strlen(accountName), accountName,
strlen(password), password,
NULL);
}
得到
+(NSString *) getPasswordKeychainWithKey: (NSString *)accountNameStr {
const char * accountName = [accountNameStr UTF8String];
void *password = nil;
UInt32 passwordLen = 0;
SecKeychainItemRef itemRef = nil;
OSStatus status1;
status1 = SecKeychainFindGenericPassword(NULL,
strlen(serviceName), serviceName,
strlen(accountName), accountName,
&passwordLen, &password,
&itemRef);
if (status1 == noErr) {
NSData* passwordData = [NSData dataWithBytes:password length:passwordLen];
SecKeychainItemFreeContent (NULL, password);
return [NSString stringWithCString:[passwordData bytes] encoding:NSUTF8StringEncoding];
}
return nil;
}