class EzCrypto::Signer
The signer is used for signing stuff. It encapsulates the functionality of a private key.
Public Class Methods
Decode a PEM encoded Private Key and return a signer. Takes an optional password
# File lib/ezsig.rb, line 56 def self.decode(encoded,password=nil) begin EzCrypto::Signer.new(OpenSSL::PKey::RSA.new( encoded,password)) rescue EzCrypto::Signer.new(OpenSSL::PKey::DSA.new( encoded,password)) end end
Decode a PEM encoded Private Key file and return a signer. Takes an optional password
# File lib/ezsig.rb, line 67 def self.from_file(filename,password=nil) file = File.read( filename ) decode(file,password) end
Generate a new keypair. Defaults to 2048 bit RSA.
# File lib/ezsig.rb, line 43 def self.generate(strength=2048,type=:rsa) key_class=case type when :dsa OpenSSL::PKey::DSA else OpenSSL::PKey::RSA end EzCrypto::Signer.new(key_class.generate(strength)) end
Public Instance Methods
Returns true if it is a DSA private key
# File lib/ezsig.rb, line 116 def dsa? @priv.is_a? OpenSSL::PKey::DSA end
Returns the OpenSSL Private Key object. You normally do not need to use this.
# File lib/ezsig.rb, line 89 def private_key @priv end
Returns the OpenSSL Public Key object. You normally do not need to use this.
# File lib/ezsig.rb, line 75 def public_key @priv.public_key end
Returns true if it is a RSA private key
# File lib/ezsig.rb, line 109 def rsa? @priv.is_a? OpenSSL::PKey::RSA end
signs data using the private key and the corresponding digest function. SHA1 for RSA and DSS1 for DSA. 99% of signing use these parameters. Email a request or send me a patch if you have other requirements.
# File lib/ezsig.rb, line 98 def sign(data) if rsa? @priv.sign(OpenSSL::Digest::SHA1.new,data) elsif dsa? @priv.sign(OpenSSL::Digest::DSS1.new,data) end end
Returns the corresponding Verifier object.
# File lib/ezsig.rb, line 82 def verifier Verifier.new(public_key) end