Class: Uits::RSA2048

Inherits:
Object
  • Object
show all
Defined in:
lib/uits.rb

Instance Method Summary collapse

Constructor Details

#initialize(path, passphrase) ⇒ RSA2048



51
52
53
54
55
56
57
58
# File 'lib/uits.rb', line 51

def initialize(path, passphrase)
  path.gsub!(/[^0-9A-Za-z]/, '')
  @passphrase = passphrase
  @private_key_path = File.join(Rails.root.to_s, "lib/.rsa", path, "id_rsa")
  @public_key_path = File.join(Rails.root.to_s, "lib/.rsa", path, "id_rsa.pub")
  @private_key = private_key
  @public_key = public_key
end

Instance Method Details

#signature(data) ⇒ Object



60
61
62
# File 'lib/uits.rb', line 60

def signature(data)
  Base64.encode64(@private_key.sign(OpenSSL::Digest::SHA1.new, data))
end

#varify?(sign, data) ⇒ Boolean



64
65
66
67
# File 'lib/uits.rb', line 64

def varify?(sign, data)
  sign = Base64.decode64(sign)
  @public_key.verify(OpenSSL::Digest::SHA1.new, sign, data)
end