{"id":19726387,"url":"https://github.com/danhunsaker/gorm-crypto","last_synced_at":"2025-10-17T11:52:20.066Z","repository":{"id":57644166,"uuid":"439217652","full_name":"danhunsaker/gorm-crypto","owner":"danhunsaker","description":"Another library for encrypting/signing data with GORM","archived":false,"fork":false,"pushed_at":"2022-05-15T22:36:16.000Z","size":175,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-17T22:40:57.150Z","etag":null,"topics":["encryption","go","go-orm","golang","gorm"],"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/danhunsaker.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":"2021-12-17T05:12:04.000Z","updated_at":"2022-01-03T12:56:00.000Z","dependencies_parsed_at":"2022-08-30T04:50:44.425Z","dependency_job_id":null,"html_url":"https://github.com/danhunsaker/gorm-crypto","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/danhunsaker/gorm-crypto","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danhunsaker%2Fgorm-crypto","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danhunsaker%2Fgorm-crypto/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danhunsaker%2Fgorm-crypto/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danhunsaker%2Fgorm-crypto/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/danhunsaker","download_url":"https://codeload.github.com/danhunsaker/gorm-crypto/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danhunsaker%2Fgorm-crypto/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267057671,"owners_count":24028870,"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","status":"online","status_checked_at":"2025-07-25T02:00:09.625Z","response_time":70,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["encryption","go","go-orm","golang","gorm"],"created_at":"2024-11-11T23:35:27.620Z","updated_at":"2025-10-17T11:52:15.018Z","avatar_url":"https://github.com/danhunsaker.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# gormcrypto\n\n![GitHub license](https://img.shields.io/github/license/danhunsaker/gorm-crypto)\n![GitHub go.mod Go version](https://img.shields.io/github/go-mod/go-version/danhunsaker/gorm-crypto)\n![GitHub Sponsors](https://img.shields.io/github/sponsors/danhunsaker)\n![Liberapay patrons](https://img.shields.io/liberapay/patrons/danhunsaker)\n\n![GitHub commits since latest release (by SemVer)](https://img.shields.io/github/commits-since/danhunsaker/gorm-crypto/latest?sort=semver)\n![GitHub Workflow Status](https://img.shields.io/github/workflow/status/danhunsaker/gorm-crypto/CI)\n[![Go Report Card](https://goreportcard.com/badge/github.com/danhunsaker/gorm-crypto)](https://goreportcard.com/report/github.com/danhunsaker/gorm-crypto)\n![Scrutinizer coverage](https://img.shields.io/scrutinizer/coverage/g/danhunsaker/gorm-crypto)\n![Scrutinizer code quality](https://img.shields.io/scrutinizer/quality/g/danhunsaker/gorm-crypto)\n\nAnother library for encrypting/signing data with GORM\n\n## Installation\n\nAs with any other Go lib, you'll want to `go get` the module:\n\n```bash\ngo get github.com/danhunsaker/gorm-crypto\n```\n\n## Usage\n\n### Code-Based Config\n\nThen, in your code, you would do something like this:\n\n```go\npackage main\n\nimport (\n    \"time\"\n\n    gc \"github.com/danhunsaker/gorm-crypto\"\n    \"github.com/danhunsaker/gorm-crypto/encoding\"\n    \"github.com/danhunsaker/gorm-crypto/encryption\"\n    \"github.com/danhunsaker/gorm-crypto/serializing\"\n    \"github.com/danhunsaker/gorm-crypto/signing\"\n)\n\nvar eKey = \"EncryptionKeyThatShouldBe32Bytes\"\nvar sKey = \"SigningKeyThatShouldBe32BytesToo\"\n\nfunc main() {\n    aes, err := encryption.NewAES256GCM(eKey)\n    if err != nil {\n        panic(err)\n    }\n\n    gc.Init(gc.Config{\n        Setups: map[time.Time]gc.Setup{\n            time.Date(2022, 1, 1, 15, 17, 35, 0, time.UTC): {\n\t\t\t\tEncoder:          encoding.Base64{},\n\t\t\t\tSerializer:       serializing.JSON{},\n\t\t\t\tEncrypter: aes,\n\t\t\t\tSigner:    signing.NewED25519FromSeed(sKey),\n            },\n        },\n    })\n}\n```\n\n### YAML-Based Config\n\nAlternately, you can do something like this:\n\n```go\npackage main\n\nimport (\n    gc \"github.com/danhunsaker/gorm-crypto\"\n)\n\nfunc main() {\n    rawConfig, _ := os.ReadFile(\"crypto.yaml\")\n    gc.Init(gc.ConfigFromBytes(rawConfig))\n}\n```\n\nAnd in `crypto.yaml`:\n\n```yaml\n\"2022-01-01T15:17:35Z\":\n  encoding:\n    algorithm: base64\n  serializing:\n    algorithm: json\n  encryption:\n    algorithm: aes256gcm\n    config:\n      key: 456E6372797074696F6E4B65795468617453686F756C64427933324279746573 # EncryptionKeyThatShouldBe32Bytes in hex\n  signing:\n    algorithm: ed25519\n    config:\n      key: 5369676E696E674B65795468617453686F756C64426533324279746573546F6F # SigningKeyThatShouldBe32BytesToo in hex\n```\n\n### Types\n\nWith that setup in place, it's as simple as using one or more of the types this library offers to encrypt and/or sign any field you like.\n\n```go\nimport \"github.com/danhunsaker/gorm-crypto/cryptypes\"\n\ntype ContrivedPersonExample struct {\n    Name    cryptypes.SignedString\n    Email   cryptypes.EncryptedString\n    Address cryptypes.NullEncryptedString\n    Phone   cryptypes.NullSignedEncryptedString\n    Age     cryptypes.SignedEncryptedUint\n}\n```\n\nAll types have a `Raw` property, which contains the unencrypted raw value - hence the name. Signed types also have a `Valid` property, which tells you\nwhether the value is untampered-with (but only when it's fresh from the DB). Null variants additionally include an `Empty` property, which indicates\nwhether the value is actually `nil` instead of whatever concrete type it would otherwise be.\n\n## Acknowledgements\n\nAs a library with similar goals and implementation, some code is very similar to\n[github.com/pkasila/gorm-crypto](https://pkg.go.dev/github.com/pkasila/gorm-crypto), which is an older library with more maintainers. If you don't\nneed the advanced features offered here, please use that fine library instead!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanhunsaker%2Fgorm-crypto","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdanhunsaker%2Fgorm-crypto","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanhunsaker%2Fgorm-crypto/lists"}