Skip to content
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

Issue integration with Ecto2? #12

Closed
erneestoc opened this issue May 21, 2016 · 5 comments
Closed

Issue integration with Ecto2? #12

erneestoc opened this issue May 21, 2016 · 5 comments

Comments

@erneestoc
Copy link

I'm attempting to use this library, followed instructions, and even read the encrypt fun inside the cipher derectory.. I keep getting this error.

** (exit) an exception was raised:
    ** (ArgumentError) argument error
        (crypto) :crypto.aes_ctr_stream_encrypt({:error, <<46, 220, 70, 162, 202, 119, 143, 51, 77, 116, 51, 201, 103, 43, 123, 112>>, <<0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0>>, 0}, "arggraarggra")
        (crypto) crypto.erl:1376: :crypto.do_stream_encrypt/2
        lib/cloak/ciphers/aes_ctr.ex:115: Cloak.AES.CTR.encrypt/2
        lib/cloak.ex:141: Cloak.encrypt/1
        lib/ecto/encrypted_binary_field.ex:12: Cloak.EncryptedBinaryField.dump/1
        (ecto) lib/ecto/type.ex:641: Ecto.Type.do_adapter_dump/3
        (ecto) lib/ecto/repo/schema.ex:595: Ecto.Repo.Schema.dump_field!/6
        (ecto) lib/ecto/repo/schema.ex:608: anonymous fn/6 in Ecto.Repo.Schema.dump_fields!/5

What am I doing wrong?

@philss
Copy link
Contributor

philss commented May 22, 2016

@erneestoc it's probably related to the key that you are using. How did you generate the key?

Try to generate your key like this:

:crypto.strong_rand_bytes(32) |> Base.encode64

This will generate a base64 string that you can use as your key:

config :cloak, Cloak.AES.CTR,
  tag: "AES",
  default: true,
  keys: [
    %{
      tag: <<1>>,
      key: :base64.decode("YOUR BASE64 KEY HERE"),
      default: true
    }
  ]

More info in this issue: #5 .

@philss
Copy link
Contributor

philss commented Jun 6, 2016

did you try to generate another key, @erneestoc?

@ghost
Copy link

ghost commented Jul 1, 2016

@philss I had the same issue with key.
This :crypto.strong_rand_bytes(32) |> Base.encode64 helped, thanks!
How about adding this as an example to README? #14

@philss
Copy link
Contributor

philss commented Jul 1, 2016

@rpelyush I agree with that. cc/ @danielberkompas

@danielberkompas
Copy link
Owner

The documentation has been updated in #14, thanks to @rpelyush. Closing this down. 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants