Object

KeyChain Class

Gives you access to the default Mac OS "classic" and Mac OS X Keychains for your applications. The KeyChain class does not provide access to internet passwords.

Properties
Handle

Methods
AddPassword
FindPassword
Lock
Unlock

# Notes

# Constructor

Name | Parameters | Description
--- | --- | ---
KeyChain | Index as Integer | Gives you a reference to any KeyChain known by the KeyChain manager. The index value should be in the range from 0 to System.KeyChainCount.

The keychain is a system-wide facility on Mac OS 8.5 and above (including Mac OS X) to store account passwords for applications. By taking advantage of the built-in keychain facility, your users won't have to type their password if their keychain is unlocked. You should always ask the user before storing something in the keychain.

An equivalent technology to the Mac OS KeyChain doesn't currently exist on other platforms, so the KeyChain class is supported only on Macintosh.

# Examples

The following example adds a KeyChainItem for an application and assigns a password

Dim NewItem as KeyChainItem
If System.KeyChainCount > 0 then
NewItem = New KeyChainItem
'Indicate the name of the application
NewItem.ServiceName = "MyApplication"
'Create a new keychain item for the application and assign the password
System.KeyChain.AddPassword NewItem, "SecretPassword"
Else
Beep
MsgBox "You don't have a key chain."
End if
Exception err as KeyChainException
MsgBox "Can't add item: " + err.Message

:

The following example retrieves the password and displays it in a message box.

Dim ItemToFind as KeyChainItem
Dim password As String
ItemToFind = New KeyChainItem
'Indicate the name of the application whose keychain item you wish to find
ItemToFind.ServiceName = "MyApplication"
'get application's password from the system keychain
password = System.KeyChain.FindPassword(ItemToFind)
MsgBox "The password for this item is: " + password
Exception err as KeyChainException
MsgBox "Can't find item: " + err.Message

# See Also

KeyChainItem class; KeyChainException error; System object.