Page 1 of 1

Calling Keychain

Posted: Tue Feb 24, 2015 3:13 pm
by vwidmer
Sorry for this but I havent tried this before so I am attempting to.

This is what I have if some one can help me with what I did wrong. I am trying to keep it in its simplest form to understand.

Thanks

Code: Select all

;OSStatus SecKeychainFindGenericPassword ( CFTypeRef keychainOrArray, UInt32 serviceNameLength, const char *serviceName, UInt32 accountNameLength, const char *accountName, UInt32 *passwordLength, void **passwordData, SecKeychainItemRef *itemRef ); 

ImportC ""
  SecKeychainFindGenericPassword (keychainOrArray.s, serviceNameLength.i, serviceName.s, accountNameLength.i, accountName.s, *passwordLength, *passwordData, *SecKeychainItemRef )
EndImport

sname.s="test"
aname.s="test"

Debug SecKeychainFindGenericPassword("",Len(sname),sname,Len(aname),aname,@passwordLength,@passwordData,@SecKeychainItemRef)
I am getting this error:

Code: Select all

Undefined symbols for architecture x86_64:
  "_SecKeychainFindGenericPassword", referenced from:
      _main in purebasic.o
      PStub_SecKeychainFindGenericPassword in purebasic.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I am referencing from here: https://developer.apple.com/library/mac ... index.html

Re: Calling Keychain

Posted: Tue Feb 24, 2015 3:39 pm
by wilbert
Your import is wrong. Try something like this ...

Code: Select all

ImportC "/System/Library/Frameworks/Security.framework/Security"
  SecKeychainFindGenericPassword(keychainOrArray, serviceNameLength, serviceName.p-utf8, accountNameLength, accountName.p-utf8, *passwordLength, *passwordData, *SecKeychainItemRef)
EndImport

Macro UTF8Len(s)
  StringByteLength(s, #PB_UTF8)
EndMacro

sname.s="test"
aname.s="test"

Debug SecKeychainFindGenericPassword(#Null, UTF8Len(sname), sname, UTF8Len(aname), aname, @passwordLength, @passwordData, @SecKeychainItemRef)

Re: Calling Keychain

Posted: Tue Feb 24, 2015 5:12 pm
by vwidmer
@wilbert: Thank you very much.. The more I see the more I learn.. I will try another one now to make sure I got it :)