Module: CmbPay::Sign
- Defined in:
- lib/cmb_pay/sign.rb
Defined Under Namespace
Modules: Sha1WithRsa
Constant Summary collapse
- CMB_PUBLIC_KEY =
File.read(File.('./public.key', __dir__)).freeze
Class Method Summary collapse
-
.encode_base64(bin) ⇒ Object
CMB replace ‘+’ with ‘*’ according to standard Base64.
- .md5_key_digest(str_key) ⇒ Object
- .rc4_encrypt(md5_hash, data) ⇒ Object
- .sha1_digest(str) ⇒ Object
Class Method Details
.encode_base64(bin) ⇒ Object
CMB replace ‘+’ with ‘*’ according to standard Base64
28 29 30 |
# File 'lib/cmb_pay/sign.rb', line 28 def self.encode_base64(bin) ::Base64.strict_encode64(bin).tr('+', '*') end |
.md5_key_digest(str_key) ⇒ Object
32 33 34 |
# File 'lib/cmb_pay/sign.rb', line 32 def self.md5_key_digest(str_key) Digest::MD5.hexdigest(str_key.encode('gb2312')).upcase end |
.rc4_encrypt(md5_hash, data) ⇒ Object
36 37 38 39 40 41 |
# File 'lib/cmb_pay/sign.rb', line 36 def self.rc4_encrypt(md5_hash, data) cipher = OpenSSL::Cipher.new('RC4') cipher.encrypt cipher.key = Util.hex_to_binary(md5_hash) cipher.update(data.encode('gb2312')) + cipher.final end |
.sha1_digest(str) ⇒ Object
43 44 45 |
# File 'lib/cmb_pay/sign.rb', line 43 def self.sha1_digest(str) OpenSSL::Digest::SHA1.hexdigest(str) end |