本文介绍了打开本地项目钥匙扣?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有人知道如何使用 SecKeychainOpen
打开Local Items钥匙串(Mavericks中的新钥匙串)?在该钥匙串中有一些条目,我想要能够请求用户使用 SecKeychainFindInternetPassword
访问的权限。
Does anyone know how to open the Local Items keychain (new in Mavericks) with SecKeychainOpen
? There are certain entries in that keychain that I'd like to be able to ask the user permission to access using SecKeychainFindInternetPassword
.
例如对于System keychain,您调用 SecKeychainOpen(/Library/Keychains/System.keychain,& keychainRef)
。
e.g. for the System keychain you call SecKeychainOpen ("/Library/Keychains/System.keychain",&keychainRef)
.
推荐答案
希望这有助于:
#include <CoreFoundation/CoreFoundation.h>
#include <Security/Security.h>
#include <CoreServices/CoreServices.h>
#include <iostream>
using namespace std;
int main (int argc, char** argv)
{
OSStatus status;
SecKeychainRef targetKeychain;
SecKeychainRef originKeychain;
SecKeychainRef newKeychain;
status = SecKeychainCreate("example.keychain", 4, "1234", false, NULL, &targetKeychain);
if(errSecDuplicateKeychain == status)
status = SecKeychainOpen("example.keychain", &targetKeychain);
cerr << "Create/Open keychain -- " << status << endl;
status = SecKeychainCopyDefault(&originKeychain);
cerr << "Get default keychain -- " << status << endl;
status = SecKeychainSetDefault(targetKeychain);
cerr << "Set default keychain -- " << status << endl;
status = SecKeychainCopyDefault(&newKeychain);
char pathName[256] = {0};
UInt32 pathLength = 256;
status = SecKeychainGetPath(newKeychain, &pathLength, pathName);
cerr << "New default keychain at path " << pathName << endl;
status = SecKeychainSetDefault(originKeychain);
cerr << "Set default keychain back -- " << status << endl;
status = SecKeychainCopyDefault(&newKeychain);
memset(pathName, 0, pathLength);
status = SecKeychainGetPath(newKeychain, &pathLength, pathName);
cerr << "Now default keychain at path " << pathName << endl;
return 0;
}
这篇关于打开本地项目钥匙扣?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!