EncryptedField
Provides an encrypted field for use in an Ecto schema.
Usage
First, configure an encryption key. An easy way to do this is with pwgen
(brew install pwgen):
brew install pwgen
pwgen -1 32
You can configure this key at runtime using a {:system, "key"} tuple:
config :encrypted_field, :key, {:system, "ENCRYPTED_FIELD_KEY"}Then, use it in an Elixir schema:
defmodule MyApp.User do
use Ecto.Schema
schema "users" do
field :token, EncryptedField
end
endWhen this value is written to the database, it will be encrypted with your secret key using AES in CTR mode, and Base64-encoded. At runtime, the value will be decrypted.
Installation
The package can be installed by adding encrypted_field to your list of
dependencies in mix.exs:
def deps do
[
{:encrypted_field, "~> 0.1.0"}
]
endDocumentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/encrypted_field.