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

    接口 SM4Options

    SM4 加密选项

    interface SM4Options {
        aad?: string | Uint8Array<ArrayBufferLike>;
        iv?: BytesLike;
        mode?: CipherModeType;
        outputFormat?: OutputFormatType;
        padding?: PaddingModeType;
        tagLength?: number;
    }

    层级 (查看层级一览)

    索引
    aad?: string | Uint8Array<ArrayBufferLike>

    GCM/CCM 模式的附加认证数据,可使用字符串或 Uint8Array

    初始化向量

    • CBC/CTR/CFB/OFB:16 字节(32 个十六进制字符)
    • GCM:12 字节(24 个十六进制字符)
    • CCM:7-13 字节(14-26 个十六进制字符,建议 12 字节)
    • ECB:不需要 IV

    加密模式 (Cipher mode)

    • ECB: 电码本模式,不需要IV (Electronic Codebook, no IV required)
    • CBC: 分组链接模式,需要IV (Cipher Block Chaining, IV required)
    • CTR: 计数器模式,需要IV,无需填充 (Counter mode, IV required, no padding)
    • CFB: 密文反馈模式,需要IV,无需填充 (Cipher Feedback, IV required, no padding)
    • OFB: 输出反馈模式,需要IV,无需填充 (Output Feedback, IV required, no padding)
    • GCM: 伽罗瓦/计数器模式,需要IV,无需填充,提供认证 (Galois/Counter Mode, IV required, no padding, provides authentication)
    • CCM: 计数器与 CBC-MAC 模式,需要 nonce,无需填充,提供认证 (Counter with CBC-MAC, nonce required, no padding, provides authentication)

    默认: ECB (Default: ECB)

    outputFormat?: OutputFormatType

    输出格式 (Output format)

    • hex: 十六进制字符串(默认,保持向后兼容)(Hex string, default for backward compatibility)
    • base64: Base64 编码字符串 (Base64 encoded string)

    默认: hex (Default: hex)

    padding?: PaddingModeType

    填充模式 (Padding mode)

    • PKCS7: PKCS#7 填充,填充值为填充字节数 (PKCS#7 padding, padding value equals padding length) 注意:JavaScript 中的 PKCS7 等同于 Java 中的 PKCS5(PKCS5 是 PKCS7 针对 8 字节块的特例) Note: PKCS7 in JavaScript is equivalent to PKCS5 in Java (PKCS5 is PKCS7 for 8-byte blocks)
    • NONE: 无填充,数据长度必须是块大小倍数 (No padding, data length must be multiple of block size)
    • ZERO: 零填充,用零字节填充 (Zero padding, pad with zero bytes)

    注意:流密码模式(CTR/CFB/OFB/GCM)不使用填充 Note: Stream cipher modes (CTR/CFB/OFB/GCM) don't use padding

    默认: PKCS7 (Default: PKCS7)

    tagLength?: number

    认证标签长度

    • GCM: 12-16 字节,默认 16
    • CCM: 4-16 字节(必须为偶数),默认 16