-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support encrypted fields in embedded schemas #84
Comments
I have posted a feature request in Ecto's Google group asking for a needed feature to support this: https://groups.google.com/d/msg/elixir-ecto/RbRdj2NFfDI/qsRLz15nAQAJ |
I'd love to see this. Just yesterday I tried using encrypted binaries on an embedded schema and then checked my database... not encrypted. Another option that would work in my case, would be to use an encrypted |
This feature is now in Ecto. Just add:
To the Ecto type and it should work in future Ecto versions. |
Tested this successfully on our app by decoding/encoding the values with 64 as suggested on the initial comment here: defmodule MyApp.EncodedBinary do
use Cloak.Ecto.Binary, vault: MyApp.Vault
def embed_as(:json), do: :dump
def dump(nil), do: {:ok, nil}
def dump(value) do
with {:ok, encrypted} <- super(value) do
{:ok, Base.encode64(encrypted)}
end
end
def load(nil), do: {:ok, nil}
def load(value), do: super(Base.decode64!(value))
end |
See #81 and #83.
Some thoughts:
dump
functions in order to trigger the encryptionThe text was updated successfully, but these errors were encountered: