董国庆
2026-02-04 b9629f1814e40cec572e51a8e3a2ccde0ab26614
laboratory/src/utils/sm4.js
@@ -1,16 +1,18 @@
import { sm4 } from 'sm-crypto';
import { getEncryptionKey, fetchEncryptionKey, getEncryptionKeyBuffer } from './encryption';
import { sm4 } from "sm-crypto";
import {
  getEncryptionKey,
  fetchEncryptionKey,
  getEncryptionKeyBuffer,
} from "./encryption";
// SM4加密函数
export const encryptBySM4 = (data) => {
    const key = fetchEncryptionKey(); // 获取当前密钥
    console.log('qweqweqwe',key);
    return sm4.encrypt(JSON.stringify(data), key);
  return sm4.encrypt(JSON.stringify(data), Buffer.from('2022lab02ora12to', 'utf-8'));
};
// SM4解密函数
export const decryptBySM4 = (data) => {
    const key = fetchEncryptionKey(); // 获取当前密钥
    return JSON.parse(sm4.decrypt(data, key));
};
  const key = fetchEncryptionKey(); // 获取当前密钥
  return JSON.parse(sm4.decrypt(data, Buffer.from('2022lab02ora12to', 'utf-8')));
};