2024-07-24 10:51:57 +08:00
|
|
|
// src/utils/encryption.js
|
|
|
|
|
import sm3 from 'sm-crypto/src/sm3'
|
2024-08-06 15:47:19 +08:00
|
|
|
import { SM_CONFIG } from './configure'
|
2024-07-24 10:51:57 +08:00
|
|
|
|
|
|
|
|
// SM3 哈希
|
2024-08-06 15:47:19 +08:00
|
|
|
export function hashSM3(text) {
|
2024-07-24 10:51:57 +08:00
|
|
|
// 对数据进行哈希计算
|
2024-08-06 15:47:19 +08:00
|
|
|
return sm3(text)
|
2024-07-24 10:51:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 使用 SM3 进行哈希并加入盐值
|
|
|
|
|
export function hashWithSM3AndSalt(text) {
|
|
|
|
|
// 将文本和盐值拼接在一起
|
2024-08-06 15:47:19 +08:00
|
|
|
const textWithSalt = SM_CONFIG.SALT + text
|
2024-07-24 10:51:57 +08:00
|
|
|
// 使用 SM3 进行哈希
|
2024-08-06 15:47:19 +08:00
|
|
|
return hashSM3(textWithSalt)
|
2024-07-24 10:51:57 +08:00
|
|
|
}
|