{"id":15603141,"url":"https://github.com/stas/active_record-pgcrypto","last_synced_at":"2025-04-16T04:59:38.899Z","repository":{"id":41158222,"uuid":"190579599","full_name":"stas/active_record-pgcrypto","owner":"stas","description":"PostgreSQL PGCrypto support for ActiveRecord","archived":false,"fork":false,"pushed_at":"2023-10-08T21:24:01.000Z","size":52,"stargazers_count":22,"open_issues_count":1,"forks_count":7,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-29T05:01:57.892Z","etag":null,"topics":["activerecord","encryption","pgcrypto","postgresql","rails","ruby"],"latest_commit_sha":null,"homepage":"","language":"Ruby","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/stas.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","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":"2019-06-06T12:43:38.000Z","updated_at":"2024-05-30T18:47:38.000Z","dependencies_parsed_at":"2024-11-01T13:14:14.184Z","dependency_job_id":null,"html_url":"https://github.com/stas/active_record-pgcrypto","commit_stats":{"total_commits":33,"total_committers":4,"mean_commits":8.25,"dds":0.1515151515151515,"last_synced_commit":"f34ebc913cb26dba033d6327af80c02a25ab864e"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stas%2Factive_record-pgcrypto","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stas%2Factive_record-pgcrypto/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stas%2Factive_record-pgcrypto/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stas%2Factive_record-pgcrypto/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stas","download_url":"https://codeload.github.com/stas/active_record-pgcrypto/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248654104,"owners_count":21140237,"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":["activerecord","encryption","pgcrypto","postgresql","rails","ruby"],"created_at":"2024-10-03T03:01:44.323Z","updated_at":"2025-04-16T04:59:38.858Z","avatar_url":"https://github.com/stas.png","language":"Ruby","readme":"# PGCrypto for ActiveRecord 🆊\n\n[PostgreSQL PGCrypto](https://www.postgresql.org/docs/current/pgcrypto.html)\nsupport for ActiveRecord models.\n\n![Don't roll your own crypto](https://imgs.xkcd.com/comics/cryptography.png)\n\n## About\n\nThe goal of this project is to provide a simple and efficient encryption\nsupport for your application records.\n\nMain goals:\n * No _magic_ please\n * No DSLs please\n * Less code, less maintenance\n * Good docs and test coverage\n * Keep it up-to-date (or at least tell people this is no longer maintained)\n\nThe available features include:\n * PostgreSQL `pgcrypto` native symmetric encryption using the\n   [attribute serialization](https://api.rubyonrails.org/classes/ActiveRecord/AttributeMethods/Serialization/ClassMethods.html#method-i-serialize) API and Arel API.\n * Logger support for sensitive data query obfuscation.\n\n### A bit of history...\n\nThe project was born after trying out `crypt_keeper` and having to deal with\nthe broken support for PostgreSQL where the stored data would be invalid for\nnative SQL functions.\n\nI would like to thank Justin for his work, but I decided to move away from the\noriginal work for arguably subjective reasons and the critical importance of\nthis functionality in my projects.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'active_record-pgcrypto'\n```\n\nAnd then execute:\n\n```ruby\n$ bundle\n```\n\nOr install it yourself as:\n\n```ruby\n$ gem install active_record-pgcrypto\n```\n\n## Usage\n\nTo start using it with ActiveRecord/Rails, add this to an initializer and\nconfigure your keys:\n```ruby\n# config/initializers/pgcrypto.rb\nrequire 'active_record/pgcrypto'\n# Replace the default environment variable name with your own value/key.\nActiveRecord::PGCrypto::SymmetricCoder.pgcrypto_key = ENV['PGCRYPTO_SYM_KEY']\n ```\n\nNow enable the coder for your model attributes:\n\n```ruby\nclass MyModel \u003c ActiveRecord::Base\n  serialize(:email, ActiveRecord::PGCrypto::SymmetricCoder)\nend\n```\n\nNOTE: In order for the encrypted data to be store the column must be of type `binary`.\n\nThe coder provides a simple API to help you provide search support by\nleveraging the Arel API:\n\n```ruby\nclass MyModel \u003c ActiveRecord::Base\n  serialize(:email, ActiveRecord::PGCrypto::SymmetricCoder)\n\n  def self.decrypted_email\n    ActiveRecord::PGCrypto::SymmetricCoder\n      .decrypted_arel_text(arel_table[:email])\n  end\nend\n```\n\nNow you can use add it to your `ActiveRecord::Base#where` queries:\n\n```ruby\nMyModel.where(MyModel.decrypted_email.matches('keyword%'))\n```\n\n## Development\n\nBuild the Docker image first:\n\n```\ndocker build -f Dockerfile -t active_record-pgcrypto/ci ./`\n```\n\nNow you can run the tests:\n\n```\ndocker run -v `pwd`:/gem -it active_record-pgcrypto/ci\n```\n\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at\nhttps://github.com/stas/active_record-pgcrypto. This project is intended to be\na safe, welcoming space for collaboration, and contributors are expected to\nadhere to the [Contributor Covenant](http://contributor-covenant.org) code of\nconduct.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n\n## Code of Conduct\n\nEveryone interacting with this project codebase, issue\ntracker, chat rooms and mailing list is expected to follow the [code of\nconduct](https://github.com/[USERNAME]/active_record-pgcrypto/blob/master/CODE_OF_CONDUCT.md).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstas%2Factive_record-pgcrypto","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstas%2Factive_record-pgcrypto","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstas%2Factive_record-pgcrypto/lists"}