Module: Crypto::RSA

Defined in:
lib/crypto-lite/sign_rsa.rb

Class Method Summary collapse

Class Method Details

.decrypt(ciphertext, public_key) ⇒ Object



19
20
21
22
# File 'lib/crypto-lite/sign_rsa.rb', line 19

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_keysObject

todo/check: add a generate alias - why? why not?



5
6
7
8
9
10
11
# File 'lib/crypto-lite/sign_rsa.rb', line 5

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



14
15
16
17
# File 'lib/crypto-lite/sign_rsa.rb', line 14

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

Returns:

  • (Boolean)


25
26
27
# File 'lib/crypto-lite/sign_rsa.rb', line 25

def self.valid_signature?( plaintext, ciphertext, public_key )
  plaintext == decrypt( ciphertext, public_key )
end