说明:python脚本批量处理加解密四要素,得到的是excel输出文件,无需额外加工处理数据;
shell脚本批量处理加解密数据,得到的数据,需要使用文本编辑器在额外处理输出的数据,最终得到加解密数据;
python脚本批量处理加解密四要素信息,使用方法:
0:使用DB工具,导出需要加解密的字段,为json文件格式,如four.json;
1:在mac主机里面安装python3和pip;
2:使用pip来安装模块xlrd、xlwt、json、requests、xlutils;
3:解压下方的zip压缩文件,进入目录,并直接在mac终端使用python3命令运行脚本:python3 fourElementDecode.py;
# coding=UTF-8
import subprocess
import json
import requests
import xlrd
import xlwt
from xlutils.copy import copy
#excel标题写入
def write_excel_xls(path, sheet_name, value):
index = len(value) # 获取需要写入数据的行数
workbook = xlwt.Workbook() # 新建一个工作簿
sheet = workbook.add_sheet(sheet_name) # 在工作簿中新建一个表格
for j in range(0, index):
sheet.write(0, j, value[j]) # 像表格中写入数据(对应的行和列)
workbook.save(path) # 保存工作簿
print("xls格式表格写入数据成功!")
#excel数据内容写入
def write_excel_xls_append(path, policylist,nameList,mobileList,idList):
index = len(policylist) # 获取需要写入数据的行数
workbook = xlrd.open_workbook(path) # 打开工作簿
sheets = workbook.sheet_names() # 获取工作簿中的所有表格
worksheet = workbook.sheet_by_name(sheets[0]) # 获取工作簿中所有表格中的的第一个表格
rows_old = worksheet.nrows # 获取表格中已存在的数据的行数
new_workbook = copy(workbook) # 将xlrd对象拷贝转化为xlwt对象
new_worksheet = new_workbook.get_sheet(0) # 获取转化后工作簿中的第一个表格
for i in range(0, index):
new_worksheet.write(i+rows_old, 0, policylist[i])
new_worksheet.write(i+rows_old, 1, nameList[i])
new_worksheet.write(i+rows_old, 2, mobileList[i])
new_worksheet.write(i+rows_old, 3, idList[i])
new_workbook.save(path) # 保存工作簿
print("xls格式表格【追加】写入数据成功!")
#调用四要素的解密接口
headers= {"Content-Type": "application/json; charset=UTF-8"}
url = "http://ip:port/path"
policylist=[]
nameList=[]
mobileList=[]
idList=[]
with open("/Users/apple/Downloads/output/20200601_20200607/20200601_20200607_four.json",encoding='utf-8') as f:
for single in json.loads(f.read())['result']:
policylist.append(single['policy_no'])
nameDec = {'key': single['full_name_encrypt'], 'method': 'Name', 'func': 'dec'}
nameDecResult = requests.post(url,str(nameDec).encode("utf-8"),headers=headers)
nameList.append(json.loads(nameDecResult.text)['value'])
mobileDec = {'key': single['mobile_encrypt'], 'method': 'Mobile', 'func': 'dec'}
mobileDecResult = requests.post(url,str(mobileDec).encode("utf-8"),headers=headers)
mobileList.append(json.loads(mobileDecResult.text)['value'])
idDec = {'key': single['govt_id_encrypt'], 'method': 'GOVTID', 'func': 'dec'}
idDecResult = requests.post(url,str(idDec).encode("utf-8"),headers=headers)
idList.append(json.loads(idDecResult.text)['value'])
book_name_xls = '20200601_20200607_four.xls'
sheet_name_xls = '四要素解密结果表'
#标题
value_title = ["保单","姓名","手机号码","身份证号码"]
write_excel_xls(book_name_xls, sheet_name_xls, value_title)
write_excel_xls_append(book_name_xls, policylist,nameList,mobileList,idList)
shell脚本批量处理加解密四要素信息,使用方法:
0:使用DB工具,导出需要加解密的字段,为txt文件格式,可见zip压缩文件里面的nameEncodeData.txt;
1:解压下方的zip压缩文件,进入目录,并直接在mac终端运行脚本:./nameDecode.sh;
#!/bin/bash
count=0
for line in $(cat nameEncodeData.txt)
do
#echo ${line}
namejson="{\"key\":\"${line}\",\"method\":\"Name\",\"func\":\"dec\"}"
#mobilejson="{\"key\":\"${line}\",\"method\":\"Mobile\",\"func\":\"dec\"}"
#idjson="{\"key\":\"${line}\",\"method\":\"GOVTID\",\"func\":\"dec\"}"
curl -k -H "Content-Type:application/json;charset=utf-8" http://ip:port/path -X POST -d "${namejson}" >> nameOutput.txt
echo >> nameOutput.txt
done