Class: Allinpay::Signature
- Inherits:
-
Object
- Object
- Allinpay::Signature
- Defined in:
- lib/allinpay/signature.rb
Class Method Summary collapse
-
.generate(str) ⇒ String
通联支付 参数加密.
-
.verify?(str, sign) ⇒ Boolean
通联支付 信息验证.
Class Method Details
.generate(str) ⇒ 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
通联支付 信息验证
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 |