数据加密和完整性校验

This commit is contained in:
jiang 2024-08-07 11:27:37 +08:00
parent 877ae77cb3
commit 700a9c6ac7
3 changed files with 70 additions and 57 deletions

View File

@ -42,9 +42,9 @@ const CONFIG = {
IS_CODE_LOGIN: LOGIN_CONFIG.CODE_EMAIL_LOGIN || LOGIN_CONFIG.CODE_PHONE_LOGIN, // 是否开启短信登录
// 数据设置
dataSettings: {
integrityCheck: DATA_SETTINGS.OPEN, // 数据完整性校验true开启false关闭
encryptRequest: DATA_SETTINGS.OPEN, // 数据传输加密true开启false关闭
encryptResponse: DATA_SETTINGS.OPEN // 数据返回解密true开启false关闭
integrityCheck: DATA_SETTINGS.CLOSE, // 数据完整性校验true开启false关闭
encryptRequest: DATA_SETTINGS.CLOSE, // 数据传输加密true开启false关闭
encryptResponse: DATA_SETTINGS.CLOSE // 数据返回解密true开启false关闭
}
}

View File

@ -40,11 +40,11 @@ service.interceptors.request.use(config => {
// 设置请求头
//入参加密
config.headers['DATA_ENCRYPT_REQUEST'] = CONFIG.dataSettings.encryptRequest && encryptRequest ? 'true' : 'false'
config.headers['encryptRequest'] = CONFIG.dataSettings.encryptRequest && encryptRequest ? 'true' : 'false'
// 数据完整性校验
config.headers['DATA_INTEGRITY'] = CONFIG.dataSettings.integrityCheck && checkIntegrity ? 'true' : 'false'
config.headers['checkIntegrity'] = CONFIG.dataSettings.integrityCheck && checkIntegrity ? 'true' : 'false'
//回参是否加密
config.headers['DATA_ENCRYPT_RESPONSE'] = CONFIG.dataSettings.encryptResponse && encryptResponse ? 'true' : 'false'
config.headers['encryptResponse'] = CONFIG.dataSettings.encryptResponse && encryptResponse ? 'true' : 'false'
const isRepeatSubmit = repeatSubmit
// 处理 Token
@ -57,11 +57,11 @@ service.interceptors.request.use(config => {
let params = tansParams(config.params).slice(0, -1)
console.log(params)
// 数据完整性校验
if (checkIntegrity) {
if (CONFIG.dataSettings.integrityCheck && checkIntegrity) {
config.headers['Params-Hash'] = hashWithSM3AndSalt(params)
}
// 加密参数
if (encryptRequest) {
if (CONFIG.dataSettings.encryptRequest && encryptRequest) {
params = encryptCBC(params)
}
config.url = `${config.url}?${params}`
@ -71,11 +71,11 @@ service.interceptors.request.use(config => {
if (!isRepeatSubmit && (config.method === 'post' || config.method === 'put')) {
let data = typeof config.data === 'object' ? JSON.stringify(config.data) : config.data
// 数据完整性校验
if (checkIntegrity) {
if (CONFIG.dataSettings.integrityCheck && checkIntegrity) {
config.headers['Params-Hash'] = hashWithSM3AndSalt(data)
}
// 加密数据
if (encryptRequest) {
if (CONFIG.dataSettings.encryptRequest && encryptRequest) {
config.data = encryptCBC(data)
}
// 检查请求数据大小

View File

@ -62,7 +62,8 @@
:disabled="multiple"
@click="handleDelete"
v-hasPermi="['system:logininfor:remove']"
>删除</el-button>
>删除
</el-button>
</el-col>
<el-col :span="1.5">
<el-button
@ -72,7 +73,8 @@
size="mini"
@click="handleClean"
v-hasPermi="['system:logininfor:remove']"
>清空</el-button>
>清空
</el-button>
</el-col>
<el-col :span="1.5">
<el-button
@ -83,7 +85,8 @@
:disabled="single"
@click="handleUnlock"
v-hasPermi="['system:logininfor:unlock']"
>解锁</el-button>
>解锁
</el-button>
</el-col>
<el-col :span="1.5">
<el-button
@ -93,23 +96,30 @@
size="mini"
@click="handleExport"
v-hasPermi="['system:logininfor:export']"
>导出</el-button>
>导出
</el-button>
</el-col>
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
</el-row>
<el-table ref="tables" v-loading="loading" :data="list" @selection-change="handleSelectionChange" :default-sort="defaultSort" @sort-change="handleSortChange">
<el-table-column type="selection" width="55" align="center" />
<el-table-column label="访问编号" align="center" prop="infoId" />
<el-table-column label="用户名称" align="center" prop="userName" :show-overflow-tooltip="true" sortable="custom" :sort-orders="['descending', 'ascending']" />
<el-table-column label="地址" align="center" prop="ipaddr" width="130" :show-overflow-tooltip="true" />
<el-table ref="tables" v-loading="loading" :data="list" @selection-change="handleSelectionChange"
:default-sort="defaultSort" @sort-change="handleSortChange"
>
<el-table-column type="selection" width="55" align="center"/>
<el-table-column label="访问编号" align="center" prop="infoId"/>
<el-table-column label="用户名称" align="center" prop="userName" :show-overflow-tooltip="true" sortable="custom"
:sort-orders="['descending', 'ascending']"
/>
<el-table-column label="地址" align="center" prop="ipaddr" width="130" :show-overflow-tooltip="true"/>
<el-table-column label="登录状态" align="center" prop="status">
<template slot-scope="scope">
<dict-tag :options="dict.type.sys_common_status" :value="scope.row.status"/>
</template>
</el-table-column>
<el-table-column label="描述" align="center" prop="msg" :show-overflow-tooltip="true" />
<el-table-column label="访问时间" align="center" prop="accessTime" sortable="custom" :sort-orders="['descending', 'ascending']" width="180">
<el-table-column label="描述" align="center" prop="msg" :show-overflow-tooltip="true"/>
<el-table-column label="访问时间" align="center" prop="accessTime" sortable="custom"
:sort-orders="['descending', 'ascending']" width="180"
>
<template slot-scope="scope">
<span>{{ parseTime(scope.row.accessTime) }}</span>
</template>
@ -127,10 +137,10 @@
</template>
<script>
import { list, delLogininfor, cleanLogininfor, unlockLogininfor } from "@/api/system/logininfor";
import { list, delLogininfor, cleanLogininfor, unlockLogininfor } from '@/api/system/logininfor'
export default {
name: "Logininfor",
name: 'Logininfor',
dicts: ['sys_common_status'],
data() {
return {
@ -143,7 +153,7 @@ export default {
//
multiple: true,
//
selectName: "",
selectName: '',
//
showSearch: true,
//
@ -153,7 +163,7 @@ export default {
//
dateRange: [],
//
defaultSort: {prop: 'accessTime', order: 'descending'},
defaultSort: { prop: 'accessTime', order: 'descending' },
//
queryParams: {
pageNum: 1,
@ -162,82 +172,85 @@ export default {
userName: undefined,
status: undefined
}
};
}
},
created() {
this.getList();
this.getList()
},
methods: {
/** 查询登录日志列表 */
getList() {
this.loading = true;
this.loading = true
list(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
this.list = response.rows;
this.total = response.total;
this.loading = false;
this.list = response.rows
this.total = response.total
this.loading = false
}
);
)
},
/** 搜索按钮操作 */
handleQuery() {
this.queryParams.pageNum = 1;
this.getList();
this.queryParams.pageNum = 1
this.getList()
},
/** 重置按钮操作 */
resetQuery() {
this.dateRange = [];
this.resetForm("queryForm");
this.queryParams.pageNum = 1;
this.dateRange = []
this.resetForm('queryForm')
this.queryParams.pageNum = 1
this.$refs.tables.sort(this.defaultSort.prop, this.defaultSort.order)
},
/** 多选框选中数据 */
handleSelectionChange(selection) {
this.ids = selection.map(item => item.infoId)
this.single = selection.length!=1
this.single = selection.length != 1
this.multiple = !selection.length
this.selectName = selection.map(item => item.userName);
this.selectName = selection.map(item => item.userName)
},
/** 排序触发事件 */
handleSortChange(column, prop, order) {
this.queryParams.orderByColumn = column.prop;
this.queryParams.isAsc = column.order;
this.getList();
this.queryParams.orderByColumn = column.prop
this.queryParams.isAsc = column.order
this.getList()
},
/** 删除按钮操作 */
handleDelete(row) {
const infoIds = row.infoId || this.ids;
const infoIds = row.infoId || this.ids
this.$modal.confirm('是否确认删除访问编号为"' + infoIds + '"的数据项?').then(function() {
return delLogininfor(infoIds);
return delLogininfor(infoIds)
}).then(() => {
this.getList();
this.$modal.msgSuccess("删除成功");
}).catch(() => {});
this.getList()
this.$modal.msgSuccess('删除成功')
}).catch(() => {
})
},
/** 清空按钮操作 */
handleClean() {
this.$modal.confirm('是否确认清空所有登录日志数据项?').then(function() {
return cleanLogininfor();
return cleanLogininfor()
}).then(() => {
this.getList();
this.$modal.msgSuccess("清空成功");
}).catch(() => {});
this.getList()
this.$modal.msgSuccess('清空成功')
}).catch(() => {
})
},
/** 解锁按钮操作 */
handleUnlock() {
const username = this.selectName;
const username = this.selectName
this.$modal.confirm('是否确认解锁用户"' + username + '"数据项?').then(function() {
return unlockLogininfor(username);
return unlockLogininfor(username)
}).then(() => {
this.$modal.msgSuccess("用户" + username + "解锁成功");
}).catch(() => {});
this.$modal.msgSuccess('用户' + username + '解锁成功')
}).catch(() => {
})
},
/** 导出按钮操作 */
handleExport() {
this.download('system/logininfor/export', {
...this.queryParams
}, `logininfor_${new Date().getTime()}.xlsx`,{ headers: { encryptResponse: false } })
}, `logininfor_${new Date().getTime()}.xlsx`, { headers: { encryptResponse: false } })
}
}
};
}
</script>