Class: Zhima::Param
- Inherits:
-
Object
- Object
- Zhima::Param
- Defined in:
- lib/zhima/param.rb
Overview
业务参数params加解密
Class Method Summary collapse
- .decrypt(param_str) ⇒ Object
-
.encrypt(params) ⇒ Object
2, identity_param: URI.encode({certNo: ‘xxx’, name: ‘xxx’, certType: ‘IDENTITY_CARD’.to_json), biz_params: URI.encode(‘M_APPPC_CERT’, channelType: ‘apppc’.to_json)} 返回两个参数:加密后的params,及sign.
- .rsa_encrypt(str) ⇒ Object
Class Method Details
.decrypt(param_str) ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/zhima/param.rb', line 23 def self.decrypt(param_str) # strict_decode64 decode64 encrypted_str = Base64.decode64 URI.decode(param_str) encrypted_str.split('').each_slice(128).inject('') do |str, bytes| str += Config.mech_rsa.private_decrypt bytes.join str end end |
.encrypt(params) ⇒ Object
2, identity_param: URI.encode({certNo: ‘xxx’, name: ‘xxx’, certType: ‘IDENTITY_CARD’.to_json), biz_params: URI.encode(‘M_APPPC_CERT’, channelType: ‘apppc’.to_json)} 返回两个参数:加密后的params,及sign
6 7 8 9 10 11 12 13 14 |
# File 'lib/zhima/param.rb', line 6 def self.encrypt(params) params = Util.symbolize_hash_keys(params) params.each { |key, value| params[key] = value.to_json if value.is_a? Hash } param_str = Util.to_query(params) [ Util.base64_encode(rsa_encrypt(param_str)), Util.base64_encode(Sign.sign(param_str)) ] end |