tonglian-ruby-sdk 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/README.md +2 -0
- data/lib/add-openssl-provider.conf +15 -0
- data/lib/tonglian-ruby-sdk.rb +47 -0
- metadata +46 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 935e1098dbe7a40b30dde67e41e4fbed3712f8bb414269088b348238ce52cdff
|
4
|
+
data.tar.gz: 2a362e859fecaa639fac8b679743f52fa1cfa054776d72dbeb88b1aebe3ffb76
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: bb31c76f7e7575ab96fce264aa71be1d89861b871b9f46094ef17144efc3e02923ac2a21d9f6af6465277180d5e1a67a4892430f127f56e9527442096d19d3d5
|
7
|
+
data.tar.gz: 51c5f40345e02fed0fc360b41ae7d7c1ce85bf1b724f72765000d5e2cb6b03acabcf4cb5657342a121a19470279da5e5ff7f08407debdbfc79b29557a1bc757b
|
data/README.md
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# to avoid error when loading PKCS12 private key file
|
2
|
+
ENV['OPENSSL_CONF'] = './add-openssl-provider.conf'
|
3
|
+
|
4
|
+
require 'openssl'
|
5
|
+
require 'cgi'
|
6
|
+
require 'digest'
|
7
|
+
require 'base64'
|
8
|
+
|
9
|
+
module TonglianRubySdk
|
10
|
+
class Signer
|
11
|
+
def initialize(private_path, private_passwd, public_path)
|
12
|
+
@private_path = private_path
|
13
|
+
@private_passwd = private_passwd
|
14
|
+
@public_path = public_path
|
15
|
+
end
|
16
|
+
|
17
|
+
def sign(params)
|
18
|
+
str = make_sign_message(params)
|
19
|
+
private_file = File.open(@private_path)
|
20
|
+
private_key = OpenSSL::PKCS12.new(private_file, @private_passwd).key.export
|
21
|
+
rsa = OpenSSL::PKey::RSA.new private_key
|
22
|
+
rsa.sign('sha1', str.force_encoding('UTF-8'))
|
23
|
+
end
|
24
|
+
|
25
|
+
def verify?(params, sign)
|
26
|
+
str = make_sign_message(params)
|
27
|
+
public_file = File.open(@public_path)
|
28
|
+
public_key = OpenSSL::X509::Certificate.new(public_file).public_key.export
|
29
|
+
rsa = OpenSSL::PKey::RSA.new(public_key)
|
30
|
+
rsa.verify('sha1', sign, str)
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def make_sign_message(params)
|
36
|
+
sorted_params = []
|
37
|
+
params.keys.sort.map do |k|
|
38
|
+
next if %w[sign signType].include? k
|
39
|
+
next if params[k].nil? || params[k].to_s.empty?
|
40
|
+
|
41
|
+
sorted_params.push("#{k}=#{CGI.escape(params[k])}")
|
42
|
+
end
|
43
|
+
|
44
|
+
Base64.encode64(Digest::MD5.hexdigest(sorted_params.join('&')))
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
metadata
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tonglian-ruby-sdk
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Yi Zhang
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-05-12 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: tonglian-ruby-sdk is a light and easy to use gem. It could help developers
|
14
|
+
quickly make use of Tonglian Payment Gateway's services.
|
15
|
+
email: yzhang.wa@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- README.md
|
21
|
+
- lib/add-openssl-provider.conf
|
22
|
+
- lib/tonglian-ruby-sdk.rb
|
23
|
+
homepage: http://github.com/yzhanginwa/tonglian-ruby-sdk
|
24
|
+
licenses:
|
25
|
+
- MIT
|
26
|
+
metadata: {}
|
27
|
+
post_install_message:
|
28
|
+
rdoc_options: []
|
29
|
+
require_paths:
|
30
|
+
- lib
|
31
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - ">="
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: 2.7.0
|
36
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
requirements: []
|
42
|
+
rubygems_version: 3.3.26
|
43
|
+
signing_key:
|
44
|
+
specification_version: 4
|
45
|
+
summary: A ruby SDK for developers to use Tong Lian payment gateway
|
46
|
+
test_files: []
|