{"id":13562073,"url":"https://github.com/99designs/go-keychain","last_synced_at":"2025-04-03T18:32:12.977Z","repository":{"id":65927144,"uuid":"50816091","full_name":"99designs/go-keychain","owner":"99designs","description":null,"archived":false,"fork":true,"pushed_at":"2022-06-29T19:33:37.000Z","size":14145,"stargazers_count":12,"open_issues_count":0,"forks_count":8,"subscribers_count":28,"default_branch":"master","last_synced_at":"2025-03-26T10:52:30.865Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"keybase/go-keychain","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/99designs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-02-01T05:20:16.000Z","updated_at":"2024-11-19T14:39:31.000Z","dependencies_parsed_at":"2023-02-16T17:16:27.492Z","dependency_job_id":null,"html_url":"https://github.com/99designs/go-keychain","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/99designs%2Fgo-keychain","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/99designs%2Fgo-keychain/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/99designs%2Fgo-keychain/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/99designs%2Fgo-keychain/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/99designs","download_url":"https://codeload.github.com/99designs/go-keychain/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247056773,"owners_count":20876457,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T13:01:04.271Z","updated_at":"2025-04-03T18:32:11.159Z","avatar_url":"https://github.com/99designs.png","language":"Go","funding_links":[],"categories":["Go"],"sub_categories":[],"readme":"# Go Keychain\n\nA library for accessing the Keychain for OSX and iOS in Go (golang).\n\nRequires OS X 10.9 or greater and iOS 8 or greater.\n\n## Usage\n\nThe API is meant to mirror the Keychain API and is not necessarily idiomatic go.\n\n#### Add Item\n\n```go\nitem := keychain.NewItem()\nitem.SetSecClass(keychain.SecClassGenericPassword)\nitem.SetService(\"MyService\")\nitem.SetAccount(\"gabriel\")\nitem.SetLabel(\"A label\")\nitem.SetAccessGroup(\"A123456789.group.com.mycorp\")\nitem.SetData([]byte(\"toomanysecrets\"))\nitem.SetSynchronizable(keychain.SynchronizableNo)\nitem.SetAccessible(keychain.AccessibleWhenUnlocked)\nerr := keychain.AddItem(item)\n\nif err == keychain.ErrorDuplicateItem {\n  // Duplicate\n}\n```\n\n#### Query Item\n\nQuery for multiple results, returning attributes:\n\n```go\nquery := keychain.NewItem()\nquery.SetSecClass(keychain.SecClassGenericPassword)\nquery.SetService(service)\nquery.SetAccount(account)\nquery.SetAccessGroup(accessGroup)\nquery.SetMatchLimit(keychain.MatchLimitAll)\nquery.SetReturnAttributes(true)\nresults, err := keychain.QueryItem(query)\nif err != nil {\n  // Error\n} else {\n  for _, r := range results {\n    fmt.Printf(\"%#v\\n\", r)\n  }\n}\n```\n\nQuery for a single result, returning data:\n\n```go\nquery := keychain.NewItem()\nquery.SetSecClass(keychain.SecClassGenericPassword)\nquery.SetService(service)\nquery.SetAccount(account)\nquery.SetAccessGroup(accessGroup)\nquery.SetMatchLimit(keychain.MatchLimitOne)\nquery.SetReturnData(true)\nresults, err := keychain.QueryItem(query)\nif err != nil {\n  // Error\n} else if len(results) != 1 {\n  // Not found\n} else {\n  password := string(results[0].Data)\n}\n```\n\n#### Delete Item\n\nDelete a generic password item with service and account:\n\n```go\nitem := keychain.NewItem()\nitem.SetSecClass(keychain.SecClassGenericPassword)\nitem.SetService(service)\nitem.SetAccount(account)\nerr := keychain.DeleteItem(item)\n```\n\n### Other\n\nThere are some convenience methods for generic password:\n\n```go\n// Create generic password item with service, account, label, password, access group\nitem := keychain.NewGenericPassword(\"MyService\", \"gabriel\", \"A label\", []byte(\"toomanysecrets\"), \"A123456789.group.com.mycorp\")\nitem.SetSynchronizable(keychain.SynchronizableNo)\nitem.SetAccessible(keychain.AccessibleWhenUnlocked)\nerr := keychain.AddItem(item)\nif err == keychain.ErrorDuplicateItem {\n  // Duplicate\n}\n\naccounts, err := keychain.GetGenericPasswordAccounts(\"MyService\")\n// Should have 1 account == \"gabriel\"\n\nerr := keychain.DeleteGenericPasswordItem(\"MyService\", \"gabriel\")\nif err == keychain.ErrorNotFound {\n  // Not found\n}\n```\n\n### OS X\n\nSet a trusted applications for item (OS X only):\n\n```go\nitem := keychain.NewGenericPassword(\"MyService\", \"gabriel\", \"A label\", []byte(\"toomanysecrets\"), \"A123456789.group.com.mycorp\")\ntrustedApplications := []string{\"/Applications/Mail.app\"}\nitem.SetAccess(\u0026keychain.Access{Label: \"Mail\", TrustedApplications: trustedApplications})\nerr := keychain.AddItem(item)\n```\n\n## iOS\n\nBindable package in `bind`. iOS project in `ios`. Run that project to test iOS.\n\nTo re-generate framework (in bind dir):\n\n```\ngomobile bind -target=ios -o ../ios/bind.framework\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F99designs%2Fgo-keychain","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F99designs%2Fgo-keychain","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F99designs%2Fgo-keychain/lists"}