Sha256: b646b78f8068bb2dd8405ad1ccb644a25d635be8c8ddcda01c3f5e2291c14365
Contents?: true
Size: 1.44 KB
Versions: 1
Compression:
Stored size: 1.44 KB
Contents
module Alipay module Sign def self.generate(params, options = {}) params = Utils.stringify_keys(params) sign_type = options[:sign_type] || Alipay.sign_type key = options[:key] || Alipay.key string = params_to_string(params) case sign_type when 'MD5' MD5.sign(key, string) when 'RSA' RSA.sign(key, string) when 'DSA' DSA.sign(key, string) else raise ArgumentError, "[Alipay] Invalid sign_type #{sign_type}, allow value: 'MD5', 'RSA', 'DSA'" end end ALIPAY_RSA_PUBLIC_KEY = <<-EOF -----BEGIN PUBLIC KEY----- MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCnxj/9qwVfgoUh/y2W89L6BkRA FljhNhgPdyPuBV64bfQNN1PjbCzkIM6qRdKBoLPXmKKMiFYnkd6rAoprih3/PrQE B/VsW8OoM8fxn67UDYuyBTqA23MML9q1+ilIZwBC2AQ2UBVOrFXfFl75p6/B5Ksi NG9zpgmLCUYuLkxpLQIDAQAB -----END PUBLIC KEY----- EOF def self.verify?(params, options = {}) params = Utils.stringify_keys(params) sign_type = params.delete('sign_type') sign = params.delete('sign') string = params_to_string(params) case sign_type when 'MD5' key = options[:key] || Alipay.key MD5.verify?(key, string, sign) when 'RSA' RSA.verify?(ALIPAY_RSA_PUBLIC_KEY, string, sign) when 'DSA' DSA.verify?(string, sign) else false end end def self.params_to_string(params) params.sort.map { |item| item.join('=') }.join('&') end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
alipay-0.6.0.beta3 | lib/alipay/sign.rb |