Last active
March 8, 2017 01:42
-
-
Save seymores/1699b3f13084f88932383566bb9a6235 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule MyApp.EncryptedField do | |
@behaviour Ecto.Type | |
def type, do: :binary | |
def cast(value) do | |
{:ok, to_string(value)} | |
end | |
# This is called when the field value is about to be written to the database | |
def dump(value) do | |
ciphertext = value |> to_string |> MyApp.EncryptionTool.encrypt | |
{:ok, ciphertext} | |
end | |
# This is called when the field is loaded from the database | |
def load(value) do | |
{:ok, MyApp.EncryptionTool.decrypt(value)} | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment