Module: Lanmao::Sign::RSA

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

Class Method Summary collapse

Class Method Details

.sign(content, private_key) ⇒ Object

签名



7
8
9
10
11
# File 'lib/lanmao/sign/rsa.rb', line 7

def self.sign(content, private_key)
  sign = private_key.sign("sha1", content.force_encoding("utf-8"))
  signature = Base64.encode64(sign)
  signature = signature.delete("\n").delete("\r")
end

.verify(data, sign, config) ⇒ Object

验签



14
15
16
17
18
19
20
21
22
# File 'lib/lanmao/sign/rsa.rb', line 14

def self.verify(data, sign, config)  ##如何从data里分离出原始数据和签名数据
  if sign
    sign = Base64.decode64(sign)
    digester = OpenSSL::Digest::SHA1.new
    config[:public_key].verify(digester, sign, data)
  else
    true
  end
end