明文加密
This commit is contained in:
parent
c63284ee05
commit
2dc4b86384
|
|
@ -229,7 +229,8 @@ export default {
|
|||
configValue: [
|
||||
{ required: true, message: "参数键值不能为空", trigger: "blur" }
|
||||
]
|
||||
}
|
||||
},
|
||||
secretKey: 'CCNWrpassWordKey'
|
||||
};
|
||||
},
|
||||
created() {
|
||||
|
|
@ -240,6 +241,15 @@ export default {
|
|||
getList() {
|
||||
this.loading = true;
|
||||
listConfig(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
|
||||
response.rows.forEach(row => {
|
||||
if (row.configKey == 'sys.user.initPassword') {
|
||||
this.decryptData(row.configValue, this.secretKey).then(data => {
|
||||
row.configValue = data;
|
||||
}).catch(err => {
|
||||
console.log('🚀 ~ decryptData ~ err:', err);
|
||||
});
|
||||
}
|
||||
});
|
||||
this.configList = response.rows;
|
||||
this.total = response.total;
|
||||
this.loading = false;
|
||||
|
|
@ -337,6 +347,26 @@ export default {
|
|||
refreshCache().then(() => {
|
||||
this.$modal.msgSuccess("刷新成功");
|
||||
});
|
||||
},
|
||||
async decryptData(encryptedData, keyStr) {
|
||||
const keyUint8 = new TextEncoder().encode(keyStr);
|
||||
const encryptedBytes = Uint8Array.from(atob(encryptedData), c => c.charCodeAt(0));
|
||||
|
||||
const key = await crypto.subtle.importKey(
|
||||
'raw',
|
||||
keyUint8,
|
||||
{ name: 'AES-CBC', length: 256 }, // 假设后端使用了CBC模式,需要调整为实际使用的模式
|
||||
false,
|
||||
['decrypt']
|
||||
);
|
||||
|
||||
const decryptedData = await crypto.subtle.decrypt(
|
||||
{ name: 'AES-CBC', iv: new Uint8Array(16) }, // 实际使用时需要正确的IV,这里仅为示例
|
||||
key,
|
||||
encryptedBytes
|
||||
);
|
||||
|
||||
return new TextDecoder().decode(decryptedData);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -410,6 +410,7 @@ export default {
|
|||
},
|
||||
],
|
||||
},
|
||||
secretKey: 'CCNWrpassWordKey'
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
|
|
@ -422,7 +423,12 @@ export default {
|
|||
this.getList()
|
||||
this.getDeptTree()
|
||||
this.getConfigKey('sys.user.initPassword').then((response) => {
|
||||
this.initPassword = response.msg
|
||||
this.decryptData(response.msg, this.secretKey).then((data) => {
|
||||
console.log('🚀 ~ this.getConfigKey ~ data:', data);
|
||||
this.initPassword = data
|
||||
}).catch((error) => {
|
||||
console.log('🚀 ~ this.getConfigKey ~ error:', error);
|
||||
})
|
||||
})
|
||||
},
|
||||
methods: {
|
||||
|
|
@ -668,6 +674,51 @@ export default {
|
|||
submitFileForm() {
|
||||
this.$refs.upload.submit()
|
||||
},
|
||||
// 加密
|
||||
async encryptData(data, keyStr) {
|
||||
const keyUint8 = new TextEncoder().encode(keyStr);
|
||||
const key = await crypto.subtle.importKey(
|
||||
'raw',
|
||||
keyUint8,
|
||||
{ name: 'AES-CBC', length: 256 },
|
||||
false,
|
||||
['encrypt']
|
||||
);
|
||||
|
||||
const iv = crypto.getRandomValues(new Uint8Array(16));
|
||||
const cipherTextBuffer = await crypto.subtle.encrypt(
|
||||
{ name: 'AES-CBC', iv },
|
||||
key,
|
||||
new TextEncoder().encode(data)
|
||||
);
|
||||
|
||||
const combined = new Uint8Array(iv.length + cipherTextBuffer.byteLength);
|
||||
combined.set(iv, 0);
|
||||
combined.set(new Uint8Array(cipherTextBuffer), iv.length);
|
||||
|
||||
return btoa(String.fromCharCode.apply(null, combined));
|
||||
},
|
||||
// 解密
|
||||
async decryptData(encryptedData, keyStr) {
|
||||
const keyUint8 = new TextEncoder().encode(keyStr);
|
||||
const encryptedBytes = Uint8Array.from(atob(encryptedData), c => c.charCodeAt(0));
|
||||
|
||||
const key = await crypto.subtle.importKey(
|
||||
'raw',
|
||||
keyUint8,
|
||||
{ name: 'AES-CBC', length: 256 }, // 假设后端使用了CBC模式,需要调整为实际使用的模式
|
||||
false,
|
||||
['decrypt']
|
||||
);
|
||||
|
||||
const decryptedData = await crypto.subtle.decrypt(
|
||||
{ name: 'AES-CBC', iv: new Uint8Array(16) }, // 实际使用时需要正确的IV,这里仅为示例
|
||||
key,
|
||||
encryptedBytes
|
||||
);
|
||||
|
||||
return new TextDecoder().decode(decryptedData);
|
||||
}
|
||||
},
|
||||
}
|
||||
</script>
|
||||
|
|
|
|||
Loading…
Reference in New Issue