2

このAPISecKeychainFindGenericPassword()を使用して空港ネットワークのパスワードを取得しようとしています。しかし、私は常にitemnotfoundエラーを受け取ります。APIでアカウント名とサービス名を何に渡すかわかりません。私がしていることを示すためにコードスニペットを追加しました。どんな助けでもいただければ幸いです。ありがとう

 OSStatus status1 ;

SecKeychainRef kychain = nil;
SecKeychainCopyDefault(&kychain);
status1 = SecKeychainFindGenericPassword (
                                          kychain,           // default keychain
                                          15,             // length of service name
                                          "AirPort Network",   // service name
                                          38,             // length of account name
                                          "com.apple.network.wlan.ssid.xxxxxxxx",   // account name
                                          passwordLength,  // length of password
                                          &passwordData,   // pointer to password data
                                          itemRef          // the item reference
                                          );
return (status1);

私はosx10.8を使用しています

4

2 に答える 2

2

サービスとアカウントが交換されました。サービスはSSIDであり、アカウント名は「AirPort」である必要があります。

SecKeychainRef keychain;
OSStatus err = SecKeychainOpen("/Library/Keychains/System.keychain", &keychain);

#define kServiceName "com.apple.network.wlan.ssid.Rackus"
#define kAccountName "AirPort"

UInt32 passwordLength = 0;
char* passwordData = nil;
UInt32 serviceNameLength = strlen(kServiceName);
UInt32 accountNameLength = strlen(kAccountName);
SecKeychainItemRef itemRef;

err = SecKeychainFindGenericPassword(keychain, serviceNameLength, kServiceName, accountNameLength, kAccountName, &passwordLength, (void**)&passwordData, &itemRef);
于 2013-10-25T23:13:17.607 に答える
0

サービス名はパスワードを取得するサービスの名前であり、アカウント名はユーザーのアカウント名です(NSUserName()を呼び出すことで取得できますが、これはNSString *を返し、このAPIはCで記述されているため注意してください。 const char *)が必要です。

すでに述べたように、KeyChain APIはCで記述されているため、プレーンCに慣れていない場合は、ラッパーライブラリを使用して作業を行うことを強くお勧めします 。https://githubをお勧めします。 com / samsoffes / sskeychain

于 2013-03-06T21:06:48.403 に答える