- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
自从升级到 OSX 10.9 Mavericks 以来,我一直无法在安全框架中使用 Keychain API,因为每次调用 Keychain 函数时,都会抛出未知异常。我尝试了钥匙串(keychain)包装器的许多不同实现,当它们调用任何钥匙串(keychain)函数时,它们都会抛出未知的异常。我什至尝试过苹果在其开发人员网站上发布的示例代码,但遇到了同样的问题。这是一个已知问题吗?如果是,修复的状态如何?现在有什么方法可以使用Keychain吗?我在下面提供了来自苹果网站的示例代码。这是链接:https://developer.apple.com/library/mac/documentation/Security/Conceptual/keychainServConcepts/03tasks/tasks.html#//apple_ref/doc/uid/TP30000897-CH205-TP9
#include <CoreFoundation/CoreFoundation.h>
#include <Security/Security.h>
#include <CoreServices/CoreServices.h>
//Call SecKeychainAddGenericPassword to add a new password to the keychain:
OSStatus StorePasswordKeychain (void* password,UInt32 passwordLength)
{
OSStatus status;
status = SecKeychainAddGenericPassword (
NULL, // default keychain
10, // length of service name
"SurfWriter", // service name
10, // length of account name
"MyUserAcct", // account name
passwordLength, // length of password
password, // pointer to password data
NULL // the item reference
);
return (status);
}
//Call SecKeychainFindGenericPassword to get a password from the keychain:
OSStatus GetPasswordKeychain (void *passwordData,UInt32 *passwordLength,
SecKeychainItemRef *itemRef)
{
OSStatus status1 ;
status1 = SecKeychainFindGenericPassword (
NULL, // default keychain
10, // length of service name
"SurfWriter", // service name
10, // length of account name
"MyUserAcct", // account name
passwordLength, // length of password
passwordData, // pointer to password data
itemRef // the item reference
);
return (status1);
}
//Call SecKeychainItemModifyAttributesAndData to change the password for
// an item already in the keychain:
OSStatus ChangePasswordKeychain (SecKeychainItemRef itemRef)
{
OSStatus status;
void * password = "myNewP4sSw0rD";
UInt32 passwordLength = strlen(password);
status = SecKeychainItemModifyAttributesAndData (
itemRef, // the item reference
NULL, // no change to attributes
passwordLength, // length of password
password // pointer to password data
);
return (status);
}
/* ********************************************************************** */
int main (int argc, const char * argv[]) {
OSStatus status;
OSStatus status1;
void * myPassword = "myP4sSw0rD";
UInt32 myPasswordLength = strlen(myPassword);
void *passwordData = nil; // will be allocated and filled in by
//SecKeychainFindGenericPassword
SecKeychainItemRef itemRef = nil;
UInt32 passwordLength = nil;
status1 = GetPasswordKeychain (&passwordData,&passwordLength,&itemRef); //Call
//SecKeychainFindGenericPassword
if (status1 == noErr) //If call was successful, authenticate user
//and continue.
{
//Free the data allocated by SecKeychainFindGenericPassword:
status = SecKeychainItemFreeContent (
NULL, //No attribute data to release
passwordData //Release data buffer allocated by
//SecKeychainFindGenericPassword
);
}
if (status1 == errSecItemNotFound) { //Is password on keychain?
/*
If password is not on keychain, display dialog to prompt user for
name and password.
Authenticate user. If unsuccessful, prompt user again for name and password.
If successful, ask user whether to store new password on keychain; if no, return.
If yes, store password:
*/
status = StorePasswordKeychain (myPassword,myPasswordLength); //Call
// SecKeychainAddGenericPassword
return (status);
}
/*
If password is on keychain, authenticate user.
If authentication succeeds, return.
If authentication fails, prompt user for new user name and password and
authenticate again.
If unsuccessful, prompt again.
If successful, ask whether to update keychain with new information. If no, return.
If yes, store new information:
*/
status = ChangePasswordKeychain (itemRef); //Call
// SecKeychainItemModifyAttributesAndData
if (itemRef) CFRelease(itemRef);
return (status);
}
最佳答案
您的申请是否已正确签名?如果不是这样,许多调用将会神秘地失败。我认为这开始发生在 10.8 左右。您收到什么错误代码?
关于cocoa - OSX 10.9 Mavericks 钥匙串(keychain) API 损坏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19886763/
我正在尝试创建一个程序,其中字符串的前三个字符重复给定次数,如下所示: foo('Chocolate', 3) # => 'ChoChoCho' foo('Abc', 3) # => 'AbcAbcA
我有以下字符串: std::string str = "Mode:AAA:val:101:id:A1"; 我想分离一个位于 "val:" 和 ":id" 之间的子字符串,这是我的方法: std::st
DNA 字符串可以是任意长度,包含 5 个字母(A、T、G、C、N)的任意组合。 压缩包含 5 个字母(A、T、G、C、N)的 DNA 字母串的有效方法是什么?不是考虑每个字母表 3 位,我们可以使用
是否有一种使用 levenstein 距离将一个特定字符串与第二个较长字符串中的任何区域进行匹配的好方法? 例子: str1='aaaaa' str2='bbbbbbaabaabbbb' if str
使用 OAuth 并使用以下函数使用我们称为“foo”(实际上是 OAuth token )的字符串加密 key public function encrypt( $text ) { // a
我是一名优秀的程序员,十分优秀!