This Gem offered 8 frequently uesed methods for Sign & Verify & Encrypt & Decrypt with RSA.
Add this line to your application's Gemfile:
gem 'rsa-tools'
And then execute:
$ bundle
Or install it yourself as:
$ gem install rsa-tools
I offered 3 pairs of methods and 2 generator method in this tool
Rsa::Tools#key_pairs
# This method will return an array of text, the first text string is private_key and the last text is public_key
Rsa::Tools.key_pairs
Rsa::Tools#pem_pairs(pub_path = nil, pri_path = nil)
# This method intend to offer you pems of key pairs, the first param is the path you want to store your private key
# And the default path is keys/private_key.pem & keys/public_key.pem
# Use the default path is my advice
Rsa::Tools.pem_pairs
Sign & Verify
# This pair of method offer the ablity to verify the source of data
# The returned signature were encoded by Base64
Rsa::Tools.sign(private_key, data) # this returns the signature
Rsa::Tools.verify(public_key, data, original_data) # this returns true or false
Encrypt & Decrypt
# I advice you use this pair while your user do not need have his own private_key (ToC)
Rsa::Tools.encrypt(private_key, data) # this returns the encrypted string
Rsa::Tools.decrypt(public_key, encrypted) # this returns the original data
PubEncrypt & PriDecrypt
# I advice you use this pair while your user should offer his public key to you (Which means ToB)
Rsa::Tools.pub_encrypt(public_key, data) # this returns the encrypted string
Rsa::Tools.pri_decrypt(private_key, encrypted) # this returns the original data
After checking out the repo, run bin/setup
to install dependencies. Then, run rake spec
to run the tests. You can also run bin/console
for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install
. To release a new version, update the version number in version.rb
, and then run bundle exec rake release
, which will create a git tag for the version, push git commits and tags, and push the .gem
file to rubygems.org.
Bug reports and pull requests are welcome on GitHub at Here. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
The gem is available as open source under the terms of the MIT License.
Everyone interacting in the Rsa::Tools project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.