提交代码

This commit is contained in:
jiang 2024-11-08 15:01:17 +08:00
parent 328e28d7ee
commit 68f09fcb7d
3 changed files with 5 additions and 15 deletions

View File

@ -2,7 +2,7 @@
export const SM_CONFIG = {
SALT: '2cc0c5f9f1749f1632efa9f63e902323', // SM3 盐值16 字节)
SM4_KEY:"78d1295afa99449b99d6f83820e6965c", // SM4 对称加密密钥
SM4_SALT:generateUUID(),
SM4_SALT:"f555adf6c01d0ab0761e626a2dae34a2",
SM2_PUBLIC_KEY: 'your-public-key', // SM2 公钥
SM2_PRIVATE_KEY: 'your-private-key' // SM2 私钥
}
@ -21,10 +21,3 @@ export function generateUUID() {
});
}
// // 使用示例
// const uuid = generateUUID();
// console.log(uuid);
// module.exports = {
// SM_CONFIG,
// AES_CONFIG,
// }

View File

@ -6,7 +6,6 @@ import errorCode from '@/utils/errorCode'
import { tansParams, blobValidate } from '@/utils/bonus'
import cache from '@/plugins/cache'
import { saveAs } from 'file-saver'
import { encryptCBC, decryptCBC } from '@/utils/aescbc'
import { decryptWithSM4, encryptWithSM4, hashWithSM3AndSalt } from '@/utils/sm'
const systemConfig = JSON.parse(localStorage.getItem('systemConfig')) || {
requestConfig: { encryptRequest: false, checkIntegrity: false, encryptResponse: false }
@ -66,6 +65,8 @@ service.interceptors.request.use(config => {
if (contentType.includes('application/json') && typeof data !== 'undefined') {
// 加密数据
if (systemConfig.requestConfig.encryptRequest && encryptRequest) {
console.log(data);
console.log(hashWithSM3AndSalt(data));
config.data = encryptWithSM4(data+"|"+hashWithSM3AndSalt(data))
}
}

View File

@ -36,8 +36,7 @@ export function decryptWithSM2(encryptedText) {
* @returns {string} 加密后的密文Hex 编码格式
*/
export function encryptWithSM4(plainText) {
const salt =SM_CONFIG.SM4_SALT
return sm4.encrypt(plainText, SM_CONFIG.SM4_KEY,{ mode: 'cbc', padding: 'pkcs#5',iv:salt})+salt;
return sm4.encrypt(plainText, SM_CONFIG.SM4_KEY,{ mode: 'cbc', padding: 'pkcs#5',iv:SM_CONFIG.SM4_SALT});
}
/**
@ -46,9 +45,6 @@ export function encryptWithSM4(plainText) {
* @returns {string} 解密后的明文
*/
export function decryptWithSM4(cipherText){
const length = cipherText.length;
const salt = length > 32 ? cipherText.substring(length - 32) : cipherText;
const originalHex = length > 32 ? cipherText.substring(0, length - 32) : '';
return SM4.decrypt(originalHex, SM_CONFIG.SM4_KEY,{ mode: 'cbc', padding: 'pkcs#5' ,iv:salt});
return SM4.decrypt(cipherText, SM_CONFIG.SM4_KEY,{ mode: 'cbc', padding: 'pkcs#5' ,iv:SM_CONFIG.SM4_SALT});
}