This package uses the security command to manipulate the keychain.
import { Keychain, KeychainFile } from '@akiojin/keychain'
const keychain = Keychain.GenerateKeychainPath('test')
await Keychain.CreateKeychain(keychain, '<Password>')
await Keychain.UnlockKeychain(keychain, '<Password>')
await Keychain.SetKeychainTimeout(keychain, 21600)
await Keychain.SetDefaultKeychain(keychain)
await Keychain.SetLoginKeychain(keychain)
await Keychain.SetListKeychain(keychain)
await Keychain.DeleteKeychain(keychain)
await Keychain.SetDefaultKeychain(Keychain.GetDefaultLoginKeychainPath())
const keychainPath = await Keychain.CreateKeychain('<Keychain name or path>', '<Password>')
const keychain = new KeychainFile(keychainPath)
keychain.SetPassword('<Password>')
keychain.Lock()
keychain.Unlock()
keychain.SetDefault()
const keychain = await KeychainFile.Open('<Keychain name or path>')
keychain.Lock()
keychain.Unlock('<Password>')
keychain.SetDefault()
Returns the keychain path given the keychain name.
This method does not create the keychain, only generates the path.
| Name |
Type |
Description |
name |
string |
The keychain name. |
| Type |
Description |
string |
keychain path |
Returns the path to login.keychain-db, which exists by default.
| Type |
Description |
string |
keychain path |
Create a new keychain and set a password.
Immediately after creation, the keychain is unlocked.
| Name |
Type |
Description |
keychain |
string |
Path of the keychain. If only the keychain name is specified, it will be placed in ~/Library/Keychains. |
password |
string |
Keychain password |
| Type |
Description |
number |
Exit code |
Import the certificate into the specified keychain.
The keychain must be unlocked.
| Name |
Type |
Description |
keychain |
string |
Path of the keychain. If no path is specified and only the keychain name is given, it is searched from ~/Library/Keychains/. |
certificate |
string |
Certificate Path |
passphrase |
string |
Certificate passphrase |
| Type |
Description |
number |
Exit code |
Change the password set for the keychain.
| Name |
Type |
Description |
keychain |
string |
Path of the keychain. If only the keychain name is specified, it will be placed in ~/Library/Keychains. |
oldPassword |
string |
Old password |
newPassword |
string |
New password |
| Type |
Description |
number |
Exit code |
Lock keychain.
If keychain is omitted, locks default keychains.
| Name |
Type |
Description |
keychain? |
string |
Path of the keychain. If no path is specified and only the keychain name is given, it is searched from ~/Library/Keychains/. |
| Type |
Description |
number |
Exit code |
Locks all keychains.
| Type |
Description |
number |
Exit code |
Unlock the keychain.
Unlock the default keychain if the keyholder is omitted.
| Name |
Type |
Description |
keychain |
string |
Path of the keychain. If no path is specified and only the keychain name is given, it is searched from ~/Library/Keychains/. |
password |
string |
Keychain password |
| Type |
Description |
number |
Exit code |
Sets the number of timeout seconds before the keychain locks without operation.
This setting also sets the lock at sleep at the same time.
| Name |
Type |
Description |
keychain |
string |
Path of the keychain. If no path is specified and only the keychain name is given, it is searched from ~/Library/Keychains/. |
seconds |
number |
Timeout in seconds (omitting this option specifies "no timeout") |
| Type |
Description |
number |
Exit code |
Deletes the specified keychain.
| Name |
Type |
Description |
keychain |
string |
Path of the keychain. If no path is specified and only the keychain name is given, it is searched from ~/Library/Keychains/. |
| Type |
Description |
number |
Exit code |
Returns the default keychain.
| Type |
Description |
string[] |
Array of keychain paths |
Sets the specified keychain as the default keychain.
| Name |
Type |
Description |
keychain |
string |
Path of the keychain. If no path is specified and only the keychain name is given, it is searched from ~/Library/Keychains/. |
| Type |
Description |
number |
Exit code |
Display the default keychain on the console.
| Type |
Description |
number |
Exit code |
Set the specified keychain as the login keychain.
| Name |
Type |
Description |
keychain |
string |
Path of the keychain. If no path is specified and only the keychain name is given, it is searched from ~/Library/Keychains/. |
| Type |
Description |
number |
Exit code |
Display the login keychain on the console.
| Type |
Description |
number |
Exit code |
Set in the key chain list.
This method overrides any other keychain list that may have been set.
| Name |
Type |
Description |
keychain |
string |
Path of the keychain. If no path is specified and only the keychain name is given, it is searched from ~/Library/Keychains/. |
| Type |
Description |
number |
Exit code |
Set in the key chain list.
This method overrides any other keychain list that may have been set.
| Name |
Type |
Description |
keychains |
string[] |
Path of the keychain. If no path is specified and only the keychain name is given, it is searched from ~/Library/Keychains/. |
| Type |
Description |
number |
Exit code |
Set permissions for Apple tools for the keychain.
Since this method is an access permission to the signature, the signature must have been imported in advance.
| Name |
Type |
Description |
keychain |
string |
Path of the keychain. If no path is specified and only the keychain name is given, it is searched from ~/Library/Keychains/. |
password |
string |
Keychain password |
| Type |
Description |
number |
Exit code |
Retrieves passwords for specified services and displays them in the console.
| Name |
Type |
Description |
service |
string |
Services to search |
| Type |
Description |
number |
Exit code |
Displays a list of certificates imported into the specified keychain.
| Name |
Type |
Description |
keychain |
string |
Path of the keychain. If no path is specified and only the keychain name is given, it is searched from ~/Library/Keychains/. |
| Type |
Description |
number |
Exit code |