• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
convert password from SecKeychainFindGenericPassword to NSString
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

convert password from SecKeychainFindGenericPassword to NSString


  • Subject: convert password from SecKeychainFindGenericPassword to NSString
  • From: Stuart Malin <email@hidden>
  • Date: Sun, 31 Jan 2010 20:51:05 -0500

I acquire a password from a keychain using SecKeychainFindGenericPassword. That provides a non null terminated c string and a length. I had been using [NSString stringWithCString: length:] to get an NSString instance of the password. However, the +stringWithCString:length: method was deprecated way back, so I thought I'd clean up my code and use +stringWithCString:encoding:  -- however that doesn't work because the  supplied C string isn't null terminated. I did a bit of searching, and found in the archives on CocoaBuilder [1] someone's solution back in September of 2005, which was to copy the acquired password to a new buffer of 1 additional byte and create a new null terminated C string there:

buffer = (char *) malloc((passwordLength + 1) * sizeof(char));
strncpy(buffer, passwordData, passwordLength);
buffer[passwordLength] = 0;
password = [NSString stringWithUTF8String:buffer];
free(buffer);

Of course I would now change the NSString class method to +stringWithCString:encoding.

Is this the best way to go about converting the string returned by the Carbon keychain code to an NSString?
I am presuming I should stop using the deprecated method -- is that right? Or can I safely continue to use it?

TIA for your wise counsel.

[1] http://www.cocoabuilder.com/archive/cocoa/145676-seckeychainfindgenericpassword.html?q=SecKeychainFindGenericPassword#145681   (expand the 22:57 post by Ryan Britton)_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: convert password from SecKeychainFindGenericPassword to NSString
      • From: "Stephen J. Butler" <email@hidden>
    • Re: convert password from SecKeychainFindGenericPassword to NSString
      • From: Kyle Sluder <email@hidden>
  • Prev by Date: NSProgressIndicator Stuck after unhiding + other triggers. Demo App.
  • Next by Date: Re: convert password from SecKeychainFindGenericPassword to NSString
  • Previous by thread: NSProgressIndicator Stuck after unhiding + other triggers. Demo App.
  • Next by thread: Re: convert password from SecKeychainFindGenericPassword to NSString
  • Index(es):
    • Date
    • Thread