Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8977921
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:29:06+00:00 2026-06-15T19:29:06+00:00

I want to store SMTP-Data from my Mac OSX application using the keychain. I

  • 0

I want to store SMTP-Data from my Mac OSX application using the keychain. I read the Keychain Services Programming Guide of Apple and wrote this method to store the data:

    - (BOOL)saveSMPTData
{
    OSStatus err;
    SecKeychainItemRef item = nil;
    SecProtocolType protocol = kSecProtocolTypeSMTP;
    const char *accessLabelUTF8 = [KEYCHAIN_NAME UTF8String];
    const char *serverNameUTF8 = [self.serverName UTF8String];
    const char *usernameUTF8 = [self.username UTF8String];
    const char *passwordUTF8 = [self.password UTF8String];

    SecAccessRef access = createAccess(KEYCHAIN_NAME);

    SecKeychainAttribute attrs[] = {
        { kSecLabelItemAttr, (int)strlen(accessLabelUTF8), (char *)accessLabelUTF8 },
        { kSecAccountItemAttr, (int)strlen(usernameUTF8), (char *)usernameUTF8 },
        { kSecServerItemAttr, (int)strlen(serverNameUTF8), (char *)serverNameUTF8 },
        { kSecProtocolItemAttr, sizeof(SecProtocolType), (SecProtocolType *)&protocol }
    };
    SecKeychainAttributeList attributes = { sizeof(attrs) / sizeof(attrs[0]), attrs };
    err = SecKeychainItemCreateFromContent(kSecInternetPasswordItemClass,
                                           &attributes,
                                           (int)strlen(passwordUTF8),
                                           passwordUTF8,
                                           NULL,
                                           access,
                                           &item);
    if (access) CFRelease(access);
    if (item) CFRelease(item);
    return (err == noErr);
}

SecAccessRef createAccess(NSString *accessLabel)
{
    OSStatus err;
    SecAccessRef access = nil;
    NSArray *trustedApplications = nil;

    SecTrustedApplicationRef myself;
    err = SecTrustedApplicationCreateFromPath(NULL, &myself);

    trustedApplications = [NSArray arrayWithObjects:(__bridge id)myself, nil];
    err = SecAccessCreate((__bridge CFStringRef)accessLabel,
                          (__bridge CFArrayRef)trustedApplications, &access);

    if (err) return nil;
    return access;
}

Of course I also want to load them. My first try looks like this:

- (BOOL)loadDataFromKeychain
{
    uint32_t serverNameLength = 0;
    const char *serverName = NULL;

    uint32_t usernameLength = 0;
    const char *username = NULL;

    uint32_t passwordLength = 0;
    void **password = NULL;

    OSStatus err = SecKeychainFindInternetPassword(NULL,
                                                   serverNameLength, serverName,
                                                   0, NULL,
                                                   usernameLength, username,
                                                   0, NULL,
                                                   0, 0,
                                                   0,
                                                   &passwordLength, password,
                                                   NULL); // How do I get the ItemRef?

    return (err == noErr);
}

But this does not work, and I think I know why not. I don’t know how to get the SecKeychainItemRef for the SecKeychainFindInternetPassword method.

Maybe anyone can help me?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T19:29:07+00:00Added an answer on June 15, 2026 at 7:29 pm

    Instead of declaring password a void **, declare it a void * and pass &password for the second-to-last parameter.

    You probably don’t need the SecKeychainItemRef for what you’re trying to accomplish.

    By the way, have you tried using Keychain Access to verify the items are getting into the keychain?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i want to store data from a XML file to the mysql am using
I want store data from an html page to a text file using javascript
I am a new developer on Android and I want store user data in
I want to store the password used for signing in a financial application that
I want to store user-clicked data in a cookie which never has to go
I want to store a very long string in database using php. The size
I want to store and retrieve data that is accessible to all activities in
I want to store merchant data in a remote database so it is PCI
I want to store large number of videos in my application's directory. Will it
I want to read unread messages from yahoo mail.so i used following code but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.