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

ExPublicKey.generate_key/2 fails. #26

Open
hickscorp opened this issue Apr 14, 2018 · 6 comments
Open

ExPublicKey.generate_key/2 fails. #26

hickscorp opened this issue Apr 14, 2018 · 6 comments

Comments

@hickscorp
Copy link

Straight from the docs:

{:ok, key} = ExPublicKey.generate_key(:rsa, 2048)

But this is what I get when running it:

** (ArgumentError) argument error
    (crypto) :crypto.rsa_generate_key_nif(:rsa, <<8, 0>>)
    (crypto) crypto.erl:543: :crypto.generate_key/3
    (public_key) public_key.erl:426: :public_key.generate_key/1
    (ex_crypto) lib/ex_public_key.ex:287: ExPublicKey.generate_key/4

Using 0.9.0.

@ntrepid8
Copy link
Owner

Which version of Elixir and Erlang are you using? What operating system?

@hickscorp
Copy link
Author

 iex --version
Erlang/OTP 20 [erts-9.3] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:10] [hipe] [kernel-poll:false]

IEx 1.6.4 (compiled with OTP 20)
uname -a
Linux Hostname 4.13.0-38-generic #43-Ubuntu SMP Wed Mar 14 15:20:44 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

@ntrepid8
Copy link
Owner

I think I see what the issue is. I can probably get it fixed in the next couple days unless you would rather send a pull-request my way with an update.

@hickscorp
Copy link
Author

@ntrepid8 Gladly yes. Tell me what's wrong and I'll fix it if I can.

@tcitworld
Copy link

@hickscorp The function you're calling is

def generate_key(bits, public_exp), do: generate_key(:rsa, bits, public_exp)

therefore you should call it like this

{:ok, key} = ExPublicKey.generate_key(2048, 65537)

or more simply

{:ok, key} = ExPublicKey.generate_key()

which has those default parameters.

@hickscorp
Copy link
Author

hickscorp commented May 17, 2018

@tcitworld Thanks, but what I was pointing out is a documentation inconsistency.
See here: https://hexdocs.pm/ex_crypto/0.9.0/ExPublicKey.html#generate_key/0

The docs seem to define a passing doctest reading {:ok, rsa_priv_key} = ExPublicKey.generate_key(:rsa, 2048). However when you run it verbatim, it fails.

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