certificate.rb 432 Bytes
require "openssl"
require 'digest/md5'

class Certificate < ActiveRecord::Base
  def key
    OpenSSL::PKey::RSA.new read_attribute(:key) if read_attribute(:key)
  end

  def cert
    OpenSSL::X509::Certificate.new read_attribute(:cert) if read_attribute(:cert)
  end

  def key_fpr
    Digest::SHA1.hexdigest(key.to_der).upcase
  end

  def cert_fpr
    Digest::SHA1.hexdigest(cert.to_der).upcase
  end
end
# vim: set et ts=2 sw=2: