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

Give example of key generation with saving keys #12

Open
ronaldtse opened this issue Jun 20, 2018 · 12 comments
Open

Give example of key generation with saving keys #12

ronaldtse opened this issue Jun 20, 2018 · 12 comments

Comments

@ronaldtse
Copy link
Contributor

I'd like to see something like this, couldn't figure out how to save generated keys in GPG or KBX formats...

# generate both a primary key and a subkey
generated = rnp.generate_key(
  primary: {
    type: 'RSA,
    length: 2048,
    userid: 'testuser',
    usage: [:sign]
  },
  sub: {
    type: 'RSA,
    length: 2048,
    usage: [:encrypt]
  }
)

# save??
@dewyatt
Copy link
Contributor

dewyatt commented Jun 20, 2018

#2 (comment)

Did you mean you want an example added to the repo?

@ronaldtse
Copy link
Contributor Author

Both 😉 Thank you @dewyatt !

@ronaldtse
Copy link
Contributor Author

Is it possible to use keys generated via Rnp.new for start_encrypt?

Something like this?

rnp.load_keys(format: 'raw', input: Rnp::Input.from_XXX)
enc = rnp.start_encrypt(
  input: Rnp::Input.from_string(plaintext),
  output: Rnp::Output.to_null
)

@ronaldtse
Copy link
Contributor Author

Oh, I see that by default Rnp.new uses 'GPG' for both:

https://github.com/riboseinc/ruby-rnp/blob/9293168068d9d9e019aefd5065bf290cbae23c63/lib/rnp/rnp.rb#L27

@ronaldtse
Copy link
Contributor Author

In particular, is it possible to only rnp.save_keys on particular keys?

@dewyatt
Copy link
Contributor

dewyatt commented Jun 20, 2018

I would like to get rid of pubfmt and secfmt for Rnp#initialize eventually as it does seem out of place (related TODO).

In particular, is it possible to only rnp.save_keys on particular keys?

Yes, but not with the #save_keys interface. I recall you can do File.write with the #public_key_data or #secret_key_data.

@ronaldtse
Copy link
Contributor Author

Indeed #public_key_data and #secret_key_data works, but once exported, how can we read them back as keys? Rnp.key_format(data) return nil on these.

@dewyatt
Copy link
Contributor

dewyatt commented Jun 20, 2018

Rnp.key_format(data) return nil on these.

I wouldn't expect it to so that would probably be a bug.

@ronaldtse
Copy link
Contributor Author

I wouldn't expect it to so that would probably be a bug.

Actually it works. Not sure what I did last night, probably just too late 👍

@dewyatt
Copy link
Contributor

dewyatt commented Jun 21, 2018

It could be that you followed my bad advice and used File.write instead of File.binwrite. Glad it's working either way.

@ronaldtse
Copy link
Contributor Author

You're probably right. I didn't try saving today 😉

@ronaldtse
Copy link
Contributor Author

I think the example should show key generation, key save (in GPG/KBX/ASCII) formats and a key load.

@dewyatt does it make more sense that we utilize a Key model on the Ruby side to manage such functionality?

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

No branches or pull requests

2 participants