> ## Documentation Index
> Fetch the complete documentation index at: https://docs.kasoftware.com/llms.txt
> Use this file to discover all available pages before exploring further.

# encEncode

> 使用指定编码格式（如 BASE64、HEX 或 SHA）编码文件或数据字符串。

export const siteNameShort = "知行之桥";

用指定编码格式编码文件或数据字符串。

## 必需的参数

必须为以下字段之一提供值，但不能同时提供：

* **data**：要编码的数据。
* **file**：要编码的文件。

## 可选的参数

* **format**：用于编码的格式。可用值为 **BASE64**、**HEX**、**HMAC**、**HTML**、**JIS**、**MD5**、**QP**、**SHA1**、**URL**、**UU** 和 **YENC**。默认值为 BASE64。
* **outfile**：用于存储编码数据的文件。
* **outformat**：编码后数据使用的格式。可用值为 **RAW**、**BASE64** 和 **HEX**。默认值为 RAW。
* **encoding**：编码前将数据转换为字节数组时使用的编码。默认值为 UTF-8。

## 输出属性

* **encodeddata**：编码后的数据。
* **format**：用于编码的格式。
* **outfile**：如果为 **outfile** 指定了输入值，则此属性为包含编码数据的文件。

## 示例

以下 {siteNameShort}Script 代码放置在 [Script 端口](../../connectors/script) 中时，会从 **\[FilePath]** 处的输入文件读取数据，使用默认 BASE64 格式对其进行编码，然后将文件推出：

```xml theme={null}
<!-- setting the file and format for the input item -->
<arc:set attr="enc.file" value="[FilePath]" />
<arc:set attr="enc.format" value="BASE64" />

<arc:call op="encEncode" in="enc" out="result">
  <!-- setting the output file data to be the encoded data returned from the operation -->
  <arc:set attr="output.data">[result.encodeddata]</arc:set>
</arc:call>

<!-- setting the filename and pushing the file out -->
<arc:set attr="output.filename" value="[FileName]" />
<arc:push item="output" />
```

## 其他资源

以下文章是使用 encEncode 操作的实际用例：

* <a href="https://www.kasoftware.com/kb/2024/01/03/http-signature-auth.html" target="_blank">使用知行之桥EDI 系统的 HTTP 签名身份验证</a>
* <a href="https://www.kasoftware.com/kb/2024/01/02/get-token.html" target="_blank">如何获取用友 ERP 的动态 Token?</a>
