Sha256: 2f27c3b5317d4663feea4d26e571dc09a61be56b911694c5f60b9af9d2c0edd4
Contents?: true
Size: 1.09 KB
Versions: 2
Compression:
Stored size: 1.09 KB
Contents
module Zhima # 业务参数params加解密 class Param # {identity_type: 2, identity_param: URI.encode({certNo: 'xxx', name: 'xxx', certType: 'IDENTITY_CARD'}.to_json), biz_params: URI.encode({auth_code: 'M_APPPC_CERT', channelType: 'apppc'}.to_json)} # 返回两个参数:加密后的params,及sign 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 def self.rsa_encrypt(str) str.split('').each_slice(117).inject('') do |s, bytes| s += Config.zm_rsa.public_encrypt(bytes.join()) s end end 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 end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
zhima-0.3.4 | lib/zhima/param.rb |
zhima-0.3.3 | lib/zhima/param.rb |