gmkitx API - v0.10.1
    正在准备搜索索引...

    变量 sm4Encrypt常量

    sm4Encrypt: (
        key: BytesLike,
        data: string | Uint8Array<ArrayBufferLike>,
        options?: SM4Options,
    ) => SM4CipherResult = sm4Functions.encrypt

    使用 SM4 加密;key、IV/nonce、mode、padding 与 AEAD 约束见 SM4Options

    类型声明

      • (
            key: BytesLike,
            data: string | Uint8Array<ArrayBufferLike>,
            options?: SM4Options,
        ): SM4CipherResult
      • 使用 SM4 加密数据 Encrypt data using SM4 block cipher

        支持的模式 (Supported modes):

        • ECB: 电码本模式 (Electronic Codebook) - 不推荐用于生产环境 (Not recommended for production)
        • CBC: 分组链接模式 (Cipher Block Chaining) - 需要IV (Requires IV)
        • CTR: 计数器模式 (Counter mode) - 流密码模式,需要IV (Stream mode, requires IV)
        • CFB: 密文反馈模式 (Cipher Feedback) - 流密码模式,需要IV (Stream mode, requires IV)
        • OFB: 输出反馈模式 (Output Feedback) - 流密码模式,需要IV (Stream mode, requires IV)
        • GCM: 伽罗瓦/计数器模式 (Galois/Counter Mode) - 认证加密,需要IV (AEAD mode, requires IV)
        • CCM: 计数器与 CBC-MAC 模式 (Counter with CBC-MAC) - 认证加密,需要 nonce (AEAD mode, requires nonce)

        支持的填充模式 (Supported padding modes):

        • PKCS7: PKCS#7 填充 (PKCS#7 padding) - 默认 (Default)
        • NONE: 无填充 (No padding) - 数据长度必须是16字节的倍数 (Data length must be multiple of 16 bytes)
        • ZERO: 零填充 (Zero padding) - 用零字节填充 (Pad with zero bytes)

        参数

        • key: BytesLike

          加密密钥(十六进制字符串,32 个字符 = 16 字节) Encryption key (hex string, 32 chars = 16 bytes)

        • data: string | Uint8Array<ArrayBufferLike>

          要加密的数据(字符串或 Uint8Array) Data to encrypt (string or Uint8Array)

        • 可选options: SM4Options

          加密选项(模式、填充、IV) Encryption options (mode, padding, IV)

        返回 SM4CipherResult

        小写十六进制字符串形式的加密数据,或GCM模式下返回包含密文和标签的对象 Encrypted data as lowercase hex string, or object with ciphertext and tag for GCM mode

        // ECB 模式
        const encrypted = encrypt(key, 'order=GMKIT-DEMO-0001&amount=88.00', { mode: CipherMode.ECB, padding: PaddingMode.PKCS7 });
        // GCM 模式(包含认证标签)
        const result = encrypt(key, 'order=GMKIT-DEMO-0001&amount=88.00', { mode: CipherMode.GCM, iv: '000000000000000000000000', aad: 'tenant=demo;schema=1' });
        console.log(result.ciphertext, result.tag);