ObjectiveC 中的钥匙串 API,而不是 C?

发布于 2024-11-30 19:46:18 字数 358 浏览 2 评论 0原文

我是 Cocoa 和 ObjectiveC 的新手,我正在编写一个基本程序,该程序使用 Web 服务让用户登录到网站。我想将凭证存储在钥匙串中,并且我在钥匙串 API 中遇到了 SecKeychainFindGenericPassword。这正是我所需要的,但该示例是用 C 编写的,而不是 ObjectiveC!

我尝试像这样调用它: [SecKeychainFindGenericPassword .. 并且自动完成建议所有参数,但类型是 const char ,而不是 NSString

ObjectiveC 中也可以使用这个函数吗?有人可以给我看一行调用这个函数的 ObjectiveC 吗?

谢谢你!

x

I'm new to Cocoa and ObjectiveC and I'm writing a basic programme that uses a web service to login a user in to a website. I want to store the credentials in the Keychain and I've come across SecKeychainFindGenericPassword in the Keychain API. It's exactly what I need, but the example is written in C, not ObjectiveC!

I've tried invoking it like this: [SecKeychainFindGenericPassword .. and the autocomplete suggests all the parameters, but the types are const char , not NSString!

Can this function be used in ObjectiveC too? Can someone please show me a line of ObjectiveC that calls this function?

Thank you!

x

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

月朦胧 2024-12-07 19:46:18

是的,可以使用该函数,但我建议使用现有的 目标-C 钥匙串包装。当您需要来自 NSString 最简单的方法是使用 UTF8String 属性。

const char *utf8str = [@"nsstring" UTF8String];

如果您想指定不同的编码,请使用 - (const char *)cStringUsingEncoding:(NSStringEncoding)encoding

例如,快速谷歌搜索会显示 此示例

error = SecKeychainFindGenericPassword(keychain, strlen([service UTF8String]), [service UTF8String], strlen([account UTF8String]), [account UTF8String], &existingPasswordLength, (void **)&existingPasswordData, &existingItem);

Yes the function can be used but I would recommend using an existing Objective-C keychain wrapper. When you need a C string from an NSString the easiest way is to use the UTF8String property.

const char *utf8str = [@"nsstring" UTF8String];

If you would like to specify a different encoding use - (const char *)cStringUsingEncoding:(NSStringEncoding)encoding

For an example a quick google search brought up this example.

error = SecKeychainFindGenericPassword(keychain, strlen([service UTF8String]), [service UTF8String], strlen([account UTF8String]), [account UTF8String], &existingPasswordLength, (void **)&existingPasswordData, &existingItem);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文