module ChanPay::Sign::RSA

Public Class Methods

sign(key, hash) click to toggle source
# File lib/chan_pay/sign/rsa.rb, line 6
def self.sign(key, hash)
  content = link_hash(hash)
  rsa = OpenSSL::PKey::RSA.new(key)
  Base64.strict_encode64(rsa.sign('sha1', content))
end
verify?(key, hash, sign) click to toggle source
# File lib/chan_pay/sign/rsa.rb, line 12
def self.verify?(key, hash, sign)
  content = link_hash(hash)
  rsa = OpenSSL::PKey::RSA.new(key)
  result = rsa.verify('sha1', Base64.strict_decode64(sign), content)
  puts "\nrsa verify:#{result}; 回过来的 sign 为:#{sign}\n" unless result
  result
end

Private Class Methods