KeychainItem
From Xojo Documentation
Class (inherits from Object)
This class is only available on the macOS platform. For cross-platform compatibility, use #If...#Endif with the Target... specifiers to make sure you will not attempt to use this class on an incompatible platform. |
Refers to a macOS Keychain item.
Properties | ||||||
|
Methods | |
|
Notes
KeychainItems can access passwords for applications only, not internet passwords.
Examples
The following example adds a KeychainItem for an application and assigns a password.
Var newItem As KeychainItem
If System.KeychainCount > 0 Then
newItem = New KeychainItem
// Indicate the name of the application
newItem.ServiceName = "MyApplication"
Try
// Create a new keychain item for the application and assign the password
System.Keychain.AddPassword(newItem, "SecretPassword")
Catch Exception error As KeychainException
MessageBox("Can't add item: " + error.Message)
End Try
Else
MessageBox("You don't have a key chain.")
End If
If System.KeychainCount > 0 Then
newItem = New KeychainItem
// Indicate the name of the application
newItem.ServiceName = "MyApplication"
Try
// Create a new keychain item for the application and assign the password
System.Keychain.AddPassword(newItem, "SecretPassword")
Catch Exception error As KeychainException
MessageBox("Can't add item: " + error.Message)
End Try
Else
MessageBox("You don't have a key chain.")
End If
The following example retrieves the password and displays it in a message box.
Var itemToFind As KeychainItem
Var password As String
itemToFind = New KeychainItem
// Indicate the name of the application whose keychain item you wish to find
itemToFind.ServiceName = "MyApplication"
Try
// get application's password from the system keychain
password = System.Keychain.FindPassword(itemToFind)
MessageBox("The password for this item is: " + password)
Catch Exception error As KeychainException
MessageBox("Can't find item: " + error.Message)
End Try
Var password As String
itemToFind = New KeychainItem
// Indicate the name of the application whose keychain item you wish to find
itemToFind.ServiceName = "MyApplication"
Try
// get application's password from the system keychain
password = System.Keychain.FindPassword(itemToFind)
MessageBox("The password for this item is: " + password)
Catch Exception error As KeychainException
MessageBox("Can't find item: " + error.Message)
End Try
See Also
Keychain class; KeychainException error; System module.