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

    变量 sm4Decrypt常量

    sm4Decrypt: (
        key: BytesLike,
        encryptedData: BytesLike | SM4CipherResult,
        options?: SM4DecryptOptions,
    ) => string = sm4Functions.decrypt

    使用 SM4 解密为 UTF-8 文本;二进制明文应使用 sm4DecryptBytes

    类型声明

      • (
            key: BytesLike,
            encryptedData: BytesLike | SM4CipherResult,
            options?: SM4DecryptOptions,
        ): string
      • 使用 SM4 解密数据 Decrypt data using SM4 block cipher

        支持的模式 (Supported modes):

        • ECB: 电码本模式 (Electronic Codebook)
        • 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和tag (AEAD mode, requires IV and tag)
        • CCM: 计数器与 CBC-MAC 模式 (Counter with CBC-MAC) - 认证加密,需要 nonce 和 tag (AEAD mode, requires nonce and tag)

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

        • PKCS7: PKCS#7 填充 (PKCS#7 padding) - 默认 (Default)
        • NONE: 无填充 (No padding)
        • ZERO: 零填充 (Zero padding)

        参数

        • key: BytesLike

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

        • encryptedData: BytesLike | SM4CipherResult

          加密的数据(十六进制字符串或 AEAD 结果对象) Encrypted data (hex string or AEAD result object)

        • 可选options: SM4DecryptOptions

          解密选项(模式、填充、IV、tag用于 GCM/CCM) Decryption options (mode, padding, IV, tag for GCM/CCM)

        返回 string

        解密后的数据(UTF-8 字符串) Decrypted data (UTF-8 string)

        // ECB 模式
        const decrypted = decrypt(key, encrypted, { mode: CipherMode.ECB, padding: PaddingMode.PKCS7 });
        // GCM 模式(校验认证标签)
        const decrypted = decrypt(key, result, { mode: CipherMode.GCM, iv: '000000000000000000000000', aad: 'metadata' });