Keychain

A simple class for working with the Mac OS X keychain.

Reference

To learn more about using the Keychain on OS X, see Apple’s Keychain Services Programming Guide and the Keychain Services Reference.

Tips

Example Usage

    # get an item
    item = Keychain::Item.new

    # add some search criteria, you need at least one, options are listed
    # in the keychain services reference 'Attribute Item Keys and Values'
    # section (link above)
    item.attributes.merge!(
            KSecAttrProtocol => KSecAttrProtocolHTTPS,
            KSecAttrServer   => 'github.com'
    )

    # work with the entry if it exists
    if item.exists?

       # cache all the metadata and print the account name (user name)
       puts item.metadata![KSecAttrAccount]

       # print the password (needs authorization)
       puts item.password

       # change the password and check it (BE CAREFUL)
       puts item.password = 'test'

       # change the user name and save to the keychain
       # note how you do not need authorization to change the user name
       item.update!( KSecAttrAccount => 'test' )
       puts item.metadata[KSecAttrAccount]

    else
       puts 'No such item exists, maybe you need different criteria?'
    end

TODO

Contributing to keychain

Copyright

Copyright © 2011 Mark Rada. See LICENSE.txt for further details.