Class: AlipayMini::Sign::RSA2

Inherits:
Object
  • Object
show all
Defined in:
lib/alipay_mini/sign/rsa2.rb

Class Method Summary collapse

Class Method Details

.sign(key, string) ⇒ Object



8
9
10
11
12
13
# File 'lib/alipay_mini/sign/rsa2.rb', line 8

def self.sign(key, string)
  pkey = OpenSSL::PKey::RSA.new(key)
  digest = OpenSSL::Digest::SHA256.new

  Base64.strict_encode64(pkey.sign(digest, string))
end

.verify?(key, string, sign) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
18
19
20
# File 'lib/alipay_mini/sign/rsa2.rb', line 15

def self.verify?(key, string, sign)
  pkey = OpenSSL::PKey::RSA.new(key)
  digest = OpenSSL::Digest::SHA256.new

  pkey.verify(digest, Base64.strict_decode64(sign), string)
end