{"id":17760811,"url":"https://github.com/negrel/secrecy","last_synced_at":"2025-03-15T10:30:54.002Z","repository":{"id":259208154,"uuid":"876670257","full_name":"negrel/secrecy","owner":"negrel","description":"🤫 A simple secret-keeping library for Go.","archived":false,"fork":false,"pushed_at":"2025-02-18T20:05:03.000Z","size":23,"stargazers_count":38,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-27T00:05:10.955Z","etag":null,"topics":["go","golang","secret"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/negrel.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-10-22T11:14:04.000Z","updated_at":"2025-02-18T19:54:08.000Z","dependencies_parsed_at":null,"dependency_job_id":"9b699545-06ba-456c-bd68-5c852717ae1f","html_url":"https://github.com/negrel/secrecy","commit_stats":null,"previous_names":["negrel/secrecy"],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/negrel%2Fsecrecy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/negrel%2Fsecrecy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/negrel%2Fsecrecy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/negrel%2Fsecrecy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/negrel","download_url":"https://codeload.github.com/negrel/secrecy/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243718770,"owners_count":20336589,"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":["go","golang","secret"],"created_at":"2024-10-26T19:13:26.227Z","updated_at":"2025-03-15T10:30:53.995Z","avatar_url":"https://github.com/negrel.png","language":"Go","funding_links":["https://www.buymeacoffee.com/negrel"],"categories":[],"sub_categories":[],"readme":"# 🤫 `secrecy` - A simple secret-keeping library for Go.\n\n\u003cp\u003e\n\t\u003ca href=\"https://pkg.go.dev/github.com/negrel/secrecy\"\u003e\n\t\t\u003cimg alt=\"PkgGoDev\" src=\"https://pkg.go.dev/badge/github.com/negrel/secrecy\"\u003e\n\t\u003c/a\u003e\n\t\u003ca href=\"https://goreportcard.com/report/github.com/negrel/secrecy\"\u003e\n\t\t\u003cimg alt=\"Go Report Card\" src=\"https://goreportcard.com/badge/github.com/negrel/secrecy\"\u003e\n\t\u003c/a\u003e\n\t\u003cimg alt=\"Go version\" src=\"https://img.shields.io/github/go-mod/go-version/prismelabs/analytics\"\u003e\n\u003c/p\u003e\n\n`secrecy` is a simple library which provides wrapper type for secret management\nin Go. It is inspired from the excellent\n[`secrecy`](https://github.com/iqlusioninc/crates/tree/main/secrecy) Rust crate.\n\nIt provides a `Secret[T]` type for wrapping another value in a secret cell which\nattempts to limit exposure (only available via the special `ExposeSecret()`\nfunction).\n\nEach secret has a [`finalizer`](https://pkg.go.dev/runtime#SetFinalizer) attached\nthat recusively zeroize secret memory when garbage collected. You must not share\nmemory contained within a secret and share the secret itself.\n\nThis helps to ensure secrets aren't accidentally copied, logged, or otherwise\nexposed (as much as possible), and also ensures secrets are securely wiped from\nmemory when garbage collected.\n\n## Getting started\n\nHere is a simple example for storing an API key.\n\n```go\npackage main\n\nimport (\n\t\"github.com/negrel/secrecy\"\n)\n\nfunc main() {\n\t// Load secret on startup.\n\tsecretApi := secrecy.NewSecretString(retrieveApiKey())\n\n\t// Then use it like this.\n\tapiCall(secretApi)\n}\n\nfunc apiCall(secret secrecy.SecretString) {\n\tapiKey := secret.ExposeSecret()\n\t// Use your API key but don't store it.\n}\n\nfunc retrieveSecret() []byte {\n\t// Securely retrieve your api key.\n}\n```\n\nIf you accidentally leak your secret using `fmt.Println`, `json.Marshal` or\nanother method, the output will contains `\u003c!SECRET_LEAKED!\u003e` marker string. You\ncan customize this value by setting the package variable\n`secrecy.SecretLeakedMarker`. This way, you can easily check for secret leaks in\nyour logs using tool such as `grep`.\n\n### Disable zeroize\n\nSometime, you must pass your secret to a library global variable such as stripe\nglobal [`Key`](https://pkg.go.dev/github.com/stripe/stripe-go/v80#pkg-variables)\nvariable.\n\nTo do so, you must disable memory zeroize as it will corrupt the exposed string\nwhen the secret will be garbage collected.\n\n```go\npackage main\n\nimport (\n\t\"github.com/negrel/secrecy\"\n\t\"github.com/stripe/stripe-go/v80\"\n)\n\nfunc main() {\n\t// Load secret on startup.\n\tstripeSecret := secrecy.NewSecretString(retrieveApiKey())\n\tstripeSecret.DisableZeroize()\n\n\tstripe.Key = stripeSecret.ExposeSecret()\n}\n\nfunc retrieveStripeSecret() []byte {\n\t// Securely retrieve your api key.\n}\n```\n\n## Contributing\n\nIf you want to contribute to `secrecy` to add a feature or improve the code contact\nme at [alexandre@negrel.dev](mailto:alexandre@negrel.dev), open an\n[issue](https://github.com/negrel/secrecy/issues) or make a\n[pull request](https://github.com/negrel/secrecy/pulls).\n\n## :stars: Show your support\n\nPlease give a :star: if this project helped you!\n\n[![buy me a coffee](https://github.com/negrel/.github/blob/master/.github/images/bmc-button.png?raw=true)](https://www.buymeacoffee.com/negrel)\n\n## :scroll: License\n\nMIT © [Alexandre Negrel](https://www.negrel.dev/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnegrel%2Fsecrecy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnegrel%2Fsecrecy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnegrel%2Fsecrecy/lists"}