rnpgp / ruby-rnp

Ruby bindings for librnp
https://www.rnpgp.org
MIT License
7 stars 3 forks source link

Support for signing #5

Closed ribose-jeffreylau closed 6 years ago

ribose-jeffreylau commented 7 years ago

Would like to use this gem to:

  1. generate key
  2. use said key to sign things like a file, a buffer, etc.

As I understand, keys are generated like so, like in the README:

key = RNP::SecretKey.generate('mypassphrase', {
  key_length: 1024,
  public_key_algorithm: RNP::PublicKeyAlgorithm::RSA,
  algorithm_params: {e: 65537},
  hash_algorithm: RNP::HashAlgorithm::SHA1,
  symmetric_key_algorithm: RNP::SymmetricKeyAlgorithm::CAST5
})

Is signing implemented? If so, how does one go about signing a file, etc.? If not, we're very much looking forward to having this feature asap! :-) Thanks!

cc: @dewyatt

dewyatt commented 6 years ago

Should be easy to do now.

require 'rnp'

rnp = Rnp.new

# generate a primary key
generated = rnp.generate_key(
  primary: {
    type: 'RSA',
    length: 1024,
    userid: 'Example User',
    usage: ['sign']
  }
)

key = generated[:primary]
# best to add some protection before saving
key.protect('password')

# we can sign without a password, because the key is still unlocked
puts rnp.sign(input: Rnp::Input.from_string('some data to sign'),
              signers: key,
              armored: true)

I apologize for it taking so long. :(