sm4Untils.ts 580 Bytes
import crypto from "gm-crypt";

let SM4 = crypto.sm4

// 加密
export const Encrypt = (word : string, key: string) => {
    const sm4Config = {
        key,
        mode: 'ecb',
        cipherType: 'base64'
    }
    const sm4 = new SM4(sm4Config)
    const ecryptedStr = sm4.encrypt(word)
    return ecryptedStr
}

// 解密
export const Decrypt = (word: string, key: string) => {
    const sm4Config = {
        key,
        mode: 'ecb',
        cipherType: 'base64'
    }
    const sm4 = new SM4(sm4Config)
    const decryptedStr = sm4.decrypt(word)
    return decryptedStr
}