class Crypto::Key

Public Class Methods

from_file(filename) click to toggle source
# File lib/crypto.rb, line 19
def self.from_file(filename)    
  self.new File.read( filename )
end
new(data) click to toggle source
# File lib/crypto.rb, line 14
def initialize(data)
  @public = (data =~ /^-----BEGIN (RSA|DSA) PRIVATE KEY-----$/).nil?
  @key = OpenSSL::PKey::RSA.new(data)
end

Public Instance Methods

decrypt(text) click to toggle source
# File lib/crypto.rb, line 27
def decrypt(text)
  @key.send("#{key_type}_decrypt", text)
end
encrypt(text) click to toggle source
# File lib/crypto.rb, line 23
def encrypt(text)
  @key.send("#{key_type}_encrypt", text)
end
key_type() click to toggle source
# File lib/crypto.rb, line 39
def key_type
  @public ? :public : :private
end
private?() click to toggle source
# File lib/crypto.rb, line 31
def private?
  !@public
end
public?() click to toggle source
# File lib/crypto.rb, line 35
def public?
  @public
end