# coding:utf-8 require 'openssl' require 'base64' #des加密并且base64编码 def des_encrypt des_key, des_text des =OpenSSL::Cipher::Cipher.new("DES-ECB") des.encrypt des.key=des_key des_text="#{des_text}" result = des.update(des_text) result << des.final data=Base64.encode64(result) data.gsub!("\n",'') end #rsa加签 base64编码 def rsa_sign data, key rkey =OpenSSL::PKey::RSA.new key sign= rkey.sign('sha1',data.force_encoding("utf-8")) signature = Base64.encode64(sign) signature.gsub!("\n",'') end #rsa加密 def rsa_encrypt data, key rsa=OpenSSL::PKey::RSA.new key result = Base64.encode64(rsa.public_encrypt data) result.gsub!("\n",'') end
#生成随机数字符串同城接口id申请更新 def random_create(len) newpass = "" 1.upto(len){ |i| newpass << rand(10).to_s} return newpass end
|
请发表评论