Module: ChanPay::Sign::RSA

Defined in:
lib/chan_pay/sign/rsa.rb

Class Method Summary collapse

Class Method Details

.sign(key, hash) ⇒ Object



6
7
8
9
10
# 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) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
15
16
17
18
# 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