Class: Allinpay::Signature

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

Class Method Summary collapse

Class Method Details

.generate(str) ⇒ String

通联支付 参数加密

Parameters:

  • str (String)

    待加密参数

Returns:

  • (String)

    加密后信息



11
12
13
14
15
16
# File 'lib/allinpay/signature.rb', line 11

def self.generate(str)
  private_file = File.open(Allinpay::Client.private_path)
  private_key= OpenSSL::PKCS12.new(private_file, Allinpay::Client.private_password).key.export
  rsa = OpenSSL::PKey::RSA.new private_key
  rsa.sign("sha1", str.force_encoding("GBK"))
end

.verify?(str, sign) ⇒ Boolean

通联支付 信息验证

Parameters:

  • str (String)

    待加密信息

  • sign (String)

    签名

Returns:

  • (Boolean)

    验证后信息



24
25
26
27
28
29
# File 'lib/allinpay/signature.rb', line 24

def self.verify?(str, sign)
  public_file = File.open(Allinpay::Client.public_path)
  public_key = OpenSSL::X509::Certificate.new(public_file).public_key.export
  rsa = OpenSSL::PKey::RSA.new(public_key)
  rsa.verify("sha1", sign, str)
end