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

Load RSA keys with passphrase #11

Closed
sheharyarn opened this issue Oct 19, 2017 · 2 comments
Closed

Load RSA keys with passphrase #11

sheharyarn opened this issue Oct 19, 2017 · 2 comments

Comments

@sheharyarn
Copy link
Contributor

I have RSA keys that are encrypted using a password. How would I go about loading them from disk and using them? Currently, when trying to load them, gives this error:

iex(11)> ExPublicKey.load("/Users/Psy/crap/crypto/testkey.pem")
{:error,
 %FunctionClauseError{arity: 1, function: :pem_entry_decode,
  module: :public_key},
 [{:public_key, :pem_entry_decode,
   [{:RSAPrivateKey,
     <<69, 103, 57, 185, 26, 114, 20, 34, 100, 84, 103, 123, 157, 128, 197, 116,
       174, 125, 94, 20, 234, 243, 138, 198, 8, 108, 207, 220, 65, 70, 93, 198,
       113, 84, 163, 100, 154, 48, 60, 9, 237, 3, ...>>,
     {'AES-128-CBC',
      <<44, 86, 151, 113, 171, 22, 39, 28, 21, 99, 173, 229, 4, 100, 138,
        3>>}}], [file: 'public_key.erl', line: 140]},
  {ExPublicKey, :load_pem_entry, 1, [file: 'lib/ex_public_key.ex', line: 63]},
  {ExPublicKey, :loads, 1, [file: 'lib/ex_public_key.ex', line: 49]},
  {:erl_eval, :do_apply, 6, [file: 'erl_eval.erl', line: 670]},
  {:elixir, :erl_eval, 3, [file: 'src/elixir.erl', line: 229]},
  {:elixir, :eval_forms, 4, [file: 'src/elixir.erl', line: 217]},
  {IEx.Evaluator, :handle_eval, 6, [file: 'lib/iex/evaluator.ex', line: 182]},
  {IEx.Evaluator, :do_eval, 4, [file: 'lib/iex/evaluator.ex', line: 175]},
  {IEx.Evaluator, :eval, 4, [file: 'lib/iex/evaluator.ex', line: 155]},
  {IEx.Evaluator, :loop, 3, [file: 'lib/iex/evaluator.ex', line: 61]}, 
  {IEx.Evaluator, :init, 4, [file: 'lib/iex/evaluator.ex', line: 21]},
  {:proc_lib, :init_p_do_apply, 3, [file: 'proc_lib.erl', line: 247]}]}
@ntrepid8
Copy link
Owner

Hmm, that isn't something that ExCrypto currently supports but I see how support could be added. We'd need to be able to supply the password to pem_entry_decode on this line:

I think we could add a load/2 function which takes the password as a 2nd argument and passes it all the way through to pem_entry_decode/2. Is that something you would want to create a PR for? If not I could probably add support for this relatively quickly.

@sheharyarn
Copy link
Contributor Author

sheharyarn commented Oct 19, 2017 via email

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

2 participants