这是一个 TypeScript 类,名为 SM4Encoder。它提供了对输入数据进行 SM4 加密的功能,并支持分块加密和压缩输入数据。其中,分块加密是指将输入数据按照一定大小分成多个块,每个块单独加密,最后将所有的加密结果拼接起来作为最终的加密结果。

类中有一些私有属性和方法,如 maxSM4Size 表示分块大小的最大值;compress 表示是否需要压缩输入数据;smTool 是一个包含各种加密算法的工具类;retB64 表示返回类型,如果为 true,则返回 base64 编码字符串,否则返回字节数组。

该类有一个公共方法 encode,用于对输入数据进行加密,并返回加密后的结果。该方法接受两个参数:postData 表示需要加密的数据;xmlhttp 是一个可选的 XMLHttpRequest 对象,暂时没有用到。

Description

下述代码创建了一个 SM4Encoder 实例,并使用其 encode 方法对字符串 'hello world' 进行加密。加密结束后,会返回一个长度为 2 的元组,第一个元素表示返回类型字符串,第二个元素表示加密后的结果。在控制台输出这两个值。

Example

const encoder = new SM4Encoder()
const [type, result] = encoder.encode('hello world')
console.log(type, result)

Hierarchy

  • SM4Encoder

Constructors

Properties

Methods

Constructors

Properties

compress: boolean = true
maxSM4Size: number = ...
retB64: boolean = !window.ArrayBuffer
smTool: SMTool

Methods

  • 对输入数据进行加密,并返回加密结果。

    Example

    // 示例代码
    const encoder = new SM4Encoder()
    const [type, result] = encoder.encode('hello world')
    console.log(type, result)

    // 输出:
    // "20" ArrayBuffer(16) { byteLength: 16 }

    Parameters

    • postData: string

      需要加密的数据。

    • Optional xmlhttp: XMLHttpRequest

      XMLHttpRequest 对象,暂时没有用到。

    Returns undefined | [string, ArrayBuffer] | [string, string]

    返回一个元组,第一个元素表示返回类型字符串,第二个元素表示加密后的结果。 返回类型字符串说明:

    • 第一位:1 表示使用 RSA 加密,0 表示未使用 RSA 加密。
    • 第二位:0 表示没有使用分块加密,1 表示使用了分块加密。
    • 第三位:0 表示未压缩,1 表示已压缩。
    • 第四位:0 表示返回字节数组,1 表示返回 base64 编码字符串。

Generated using TypeDoc