Class: EzCrypto::Signer

### Home Classes Methods

### In Files

- lib/ezsig.rb

### Parent

Object

### Methods

- ::decode
- ::from_file
- ::generate
- ::new
- #dsa?
- #private_key
- #public_key
- #rsa?
- #sign
- #verifier

### Files

- CHANGELOG
- README.rdoc
- README_ACTIVE_CRYPTO
- README_DIGITAL_SIGNATURES

### Class/Module Index

Quicksearch

- EzCrypto
- EzCrypto::Certificate
- EzCrypto::Digester
- EzCrypto::Key
- EzCrypto::Name
- EzCrypto::Signer
- EzCrypto::TrustStore
- EzCrypto::Verifier
- ActiveCrypto
- ActiveCrypto::AssociationKeyHolder
- ActiveCrypto::ClassMethods
- ActiveCrypto::Encrypted
- ActiveCrypto::Encrypted::ClassAccessors
- ActiveCrypto::KeyHolder
- ActiveCrypto::MissingKeyError

No matching classes.

# EzCrypto::Signer

The signer is used for signing stuff. It encapsulates the functionality of a private key.

### Public Class Methods

decode(encoded,password=nil) click to toggle source

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

from_file(filename,password=nil) click to toggle source

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(strength=2048,type=:rsa) click to toggle source

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

new(priv,options = {}) click to toggle source

Initialize a Signer with a OpenSSL Private Key. You generally should not call new directly. Unless you are interfacing with your own underlying OpenSSL code.

    # File lib/ezsig.rb, line 36
    def initialize(priv,options = {})
      @priv=priv
    end

### Public Instance Methods

dsa?() click to toggle source

Returns true if it is a DSA private key

    # File lib/ezsig.rb, line 116
    def dsa?
      @priv.is_a? OpenSSL::PKey::DSA
    end

private_key() click to toggle source

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

public_key() click to toggle source

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

rsa?() click to toggle source

Returns true if it is a RSA private key

    # File lib/ezsig.rb, line 109
    def rsa?
      @priv.is_a? OpenSSL::PKey::RSA
    end

sign(data) click to toggle source

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

verifier() click to toggle source

Returns the corresponding Verifier object.

    # File lib/ezsig.rb, line 82
    def verifier
      Verifier.new(public_key)
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.