如何从iPhone应用程序检索钥匙串?

时间:2021-04-12 13:43:45

I store password to the keychain when the user logs in. Now I'm working on change password page. I want to compare the keychain password with old password. How do I retrieve the keychain password?

我在用户登录时将密码存储到钥匙串中。现在我正在处理更改密码页面。我想比较钥匙串密码和旧密码。如何检索钥匙串密码?

I'm using ASIHttpRequest to validate user. ASIHttpRequest stores the password in the keychain.

我正在使用ASIHttpRequest来验证用户。 ASIHttpRequest将密码存储在钥匙串中。

[request setUseKeychainPersistence:YES];
[request setShouldPresentAuthenticationDialog:TRUE];
[request setShouldPresentCredentialsBeforeChallenge:TRUE];

Can someone help me how do I get the stored password from Keychain?

有人可以帮我如何从Keychain获取存储的密码?

2 个解决方案

#1


1  

Since you're using ASIHTTPRequest, you can use its keychain interface in ASIHTTPRequest.h:

由于您使用的是ASIHTTPRequest,因此可以在ASIHTTPRequest.h中使用其keychain接口:

// Return credentials from the keychain
+ (NSURLCredential *)savedCredentialsForHost:(NSString *)host port:(int)port protocol:(NSString *)protocol realm:(NSString *)realm;

There are several other routines that should be of interest in that file. Search for "keychain".

在该文件中还有其他一些应该感兴趣的例程。搜索“钥匙串”。

#2


0  

This following simple blog post about keychain help me to store and retrieve keychain values from iphone app. As Rob Napier posted answer to ASIHttpRequest framework but I found it bit complicated and I started using Apple KeychainItemWrapper class and it's very easy to implement. I will mark this as answer to my question.

以下关于钥匙串的简单博客文章帮助我从iphone应用程序存储和检索钥匙串值。正如Rob Napier发布ASIHttpRequest框架的答案,但我发现它有点复杂,我开始使用Apple KeychainItemWrapper类,它很容易实现。我将此标记为我的问题的答案。

#1


1  

Since you're using ASIHTTPRequest, you can use its keychain interface in ASIHTTPRequest.h:

由于您使用的是ASIHTTPRequest,因此可以在ASIHTTPRequest.h中使用其keychain接口:

// Return credentials from the keychain
+ (NSURLCredential *)savedCredentialsForHost:(NSString *)host port:(int)port protocol:(NSString *)protocol realm:(NSString *)realm;

There are several other routines that should be of interest in that file. Search for "keychain".

在该文件中还有其他一些应该感兴趣的例程。搜索“钥匙串”。

#2


0  

This following simple blog post about keychain help me to store and retrieve keychain values from iphone app. As Rob Napier posted answer to ASIHttpRequest framework but I found it bit complicated and I started using Apple KeychainItemWrapper class and it's very easy to implement. I will mark this as answer to my question.

以下关于钥匙串的简单博客文章帮助我从iphone应用程序存储和检索钥匙串值。正如Rob Napier发布ASIHttpRequest框架的答案,但我发现它有点复杂,我开始使用Apple KeychainItemWrapper类,它很容易实现。我将此标记为我的问题的答案。