Module: Crypto::RSA
- Defined in:
- lib/crypto-lite.rb
Class Method Summary collapse
- .decrypt(ciphertext, public_key) ⇒ Object
-
.generate_keys ⇒ Object
todo/check: add a generate alias - why? why not?.
- .sign(plaintext, private_key) ⇒ Object
- .valid_signature?(plaintext, ciphertext, public_key) ⇒ Boolean
Class Method Details
.decrypt(ciphertext, public_key) ⇒ Object
264 265 266 267 |
# File 'lib/crypto-lite.rb', line 264 def self.decrypt( ciphertext, public_key ) public_key = OpenSSL::PKey::RSA.new( public_key ) ## note: convert/wrap into to obj from exported text format public_key.public_decrypt( Base64.decode64( ciphertext )) end |
.generate_keys ⇒ Object
todo/check: add a generate alias - why? why not?
250 251 252 253 254 255 256 |
# File 'lib/crypto-lite.rb', line 250 def self.generate_keys ## todo/check: add a generate alias - why? why not? key_pair = OpenSSL::PKey::RSA.new( 2048 ) private_key = key_pair.export public_key = key_pair.public_key.export [private_key, public_key] end |
.sign(plaintext, private_key) ⇒ Object
259 260 261 262 |
# File 'lib/crypto-lite.rb', line 259 def self.sign( plaintext, private_key ) private_key = OpenSSL::PKey::RSA.new( private_key ) ## note: convert/wrap into to obj from exported text format Base64.encode64( private_key.private_encrypt( plaintext )) end |
.valid_signature?(plaintext, ciphertext, public_key) ⇒ Boolean
270 271 272 |
# File 'lib/crypto-lite.rb', line 270 def self.valid_signature?( plaintext, ciphertext, public_key ) plaintext == decrypt( ciphertext, public_key ) end |