KeychainException
From Xojo Documentation
Class (inherits from RuntimeException)
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. |
A method of the Keychain or KeychainItem classes failed. See the error code returned by KeychainException to diagnose the problem.
Properties | |||
|
Methods | ||
|
Notes
The following tables shows the values of ErrorNumber and the associated text returned in the Message property.
Error Number | Message |
---|---|
-128 | User Cancelled. |
-25291 | Keychain not available. |
-25292 | Keychain read only. |
-25293 | Keychain Authorization failed. |
-25294 | No such Keychain. |
-25295 | Invalid Keychain. |
-25296 | Duplicate Keychain. |
-25797 | Keychain Duplicate Callback. |
-25298 | Keychain Invalid Callback. |
-25299 | Keychain Duplicate Item. |
-25300 | Keychain Item Not Found. |
-25301 | Keychain Buffer Too Small. |
-25302 | Keychain Data Too Large. |
-25303 | Keychain No Such Attribute. |
-25304 | Keychain Invalid Item Reference. |
-25305 | Keychain Invalid Search Reference. |
-25306 | Keychain No Such Class. |
-25307 | No Default Keychain. |
-25308 | Keychain Interaction Not Allowed. |
-25309 | Keychain Read Only Attribute. |
-25310 | Wrong Keychain Version. |
-25311 | Keychain Key Size Not Allowed. |
-25312 | Keychain No Storage Module. |
-25313 | Keychain No Certificate Module. |
-25314 | Keychain No Policy Module. |
-25315 | Keychain Interaction Required. |
-25316 | Keychain Data Not Available. |
-25317 | Keychain Data Not Modifiable. |
-25318 | Keychain Create Chain Failed. |
Sample Code
The following example displays a message box if, for example, you try to create more than one KeychainItem for the same application.
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 error As KeychainException
MessageBox(error.Message + ". Error Code: " + error.errorNumber.ToString)
End Try
Else
Beep
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 error As KeychainException
MessageBox(error.Message + ". Error Code: " + error.errorNumber.ToString)
End Try
Else
Beep
MessageBox("You don't have a key chain.")
End If
The following example uses an Exception block to display a message box if the application specified by ServiceName does not have a KeychainItem.
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 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 error As KeychainException
MessageBox("Can't find item: " + error.Message)
End Try
See Also
Keychain, KeychainItem, RuntimeException classes; System module.