---
title: "安全功能 - 导数工具 V4.3.3 | OceanBase 文档中心"
description: 安全功能 导数工具默认在命令行中显式指定密码等敏感信息即可运行。为了加强信息的安全性，导数工具 4.2.0 及之后的版本支持对命令行中的敏感信息提供加密和解密的方法。 快速上手：使用 secure-gen 加密 安装 OpenSSL 并配置环境变量。 说明 使用 secure-gen 加密时，需要安装 OpenSSL…
---
切换语言

- 中文站 - 简体中文
- International - English
- 日本站 - 日本語

文档反馈![](https://mdn.alipayobjects.com/huamei_22khvb/afts/img/A*eAudSaxX8P0AAAAAAAAAAAAADiGDAQ/original) 导数工具V 4.3.3

# 安全功能

更新时间：2026-04-13 12:00:53

[编辑](https://github.com/oceanbase/obdumper-loader-doc/edit/V4.3.3/zh-CN/700.obloaderobdumper-encryption.md)  

导数工具默认在命令行中显式指定密码等敏感信息即可运行。为了加强信息的安全性，导数工具 4.2.0 及之后的版本支持对命令行中的敏感信息提供加密和解密的方法。

## 快速上手：使用 secure-gen 加密

1. 安装 [OpenSSL](https://www.openssl.org/source/?spm=a2c4g.42216.0.0.7097553fHQEFiE) 并配置环境变量。

   #### 说明

   使用 secure-gen 加密时，需要安装 OpenSSL 工具包。具体请参考本节的 **查看 secure-gen 帮助** 内容。
 2. 确认 OpenSSL 已安装成功。

   ```shell
   $ which openssl

   /usr/bin/openssl

   ```
 3. 加密本地路径下的敏感文件。

   ```shell
   ./secure-gen -n <file_path>

   ```

   #### 说明

   敏感文件的格式需要符合 [Property File Format 规范](https://docs.oracle.com/cd/E23095_01/Platform.93/ATGProgGuide/html/s0204propertiesfileformat01.html) 或者在交互界面中编辑待加密的敏感信息。

      1. 在 `{ob-loader-dumper}/tools/` 目录下执行以下命令。

        ```shell
        ./secure-gen -i

        ```
      2. 在交互窗口中编辑需要加密的参数，完成后请输入 `:wq` 保存并退出。

        ```shell
        # Input the sensitive fields below in plain-text respectively.
        # Note you can leave any of them as blank, ob-loader-dumper will parse from cli args first, and override any field if there is a conflict。
        #
        # Database password.
        oceanbase.jdbc.password=******
        # Database password for sys tenant.
        oceanbase.jdbc.sys.password=******
        # Access key for cloud storages like OSS & S3.
        cloud.storage.access.key=******
        # Secret key for cloud storages like OSS & S3.
        cloud.storage.secret.key=******  

        :wq

        ```

        目前导数工具支持加密的敏感参数包括：

        | **参数** | **说明** |
        | --- | --- |
        | oceanbase.jdbc.password | 非必选项。OceanBase 业务租户的密码，即命令行选项 [`-p(--password)`](https://www.oceanbase.com/docs/common-oceanbase-dumper-loader-1000000002401638) 所指定的值。 |
        | oceanbase.jdbc.sys.password | 非必选项。OceanBase sys 租户下的账户密码，即命令行选项 `--sys-password` 所指定的值。 |
        | cloud.storage.access.key | 非必选项。适用于云存储服务（S3/OSS），即命令行选项 `-f` 所指定的访问账号 `access-key`。 |
        | cloud.storage.secret.key | 非必选项。适用于云存储服务（S3/OSS），即命令行选项 `-f` 所指定的访问密钥 `secret-key`。 |
 4. 如果密钥已存在，可根据提示选择是否使用已存在的密钥。

   ```shell
   $ ./secure-gen
   Detected that a key already exists, do you want to use it?
   If not, a new key will be generated and overwrite the existing key (y/n):

   ```

      1. 输入 `n` 表示通过 OpenSSL 重新生成密钥对，默认密钥对的存放路径为 `<用户根目录>/.loaddump/secure/`。公钥文件默认是 `key.pem.pub`，私钥文件默认是 `key.pem`。

        ```shell
        Detected that a key already exists, do you want to use it?
        If not, a new key will be generated and overwrite the existing key (y/n): n
        Generating RSA private key, 4096 bit long modulus
        ............++
        .......................................................++
        e is 65537 (0x10001)
        writing RSA key

        The key pair has been generated under the directory /Users/chang/.loaddump, please keep it safe.
        The encrypted file /Users/chang/.loaddump/secure/secure.rsa has been generated for sensitive information.

        If you want to use it, please fill in the corresponding content in conf/decrypt.properties properly.

        ```
      2. 输入 `y` 表示使用已存在的密钥对，导数工具从 `<用户根目录>/.loaddump/secure/` 目录中加载密钥对并生成加密文件（`secure.rsa`）。

        ```shell
        Detected that a key already exists, do you want to use it? If not, a new key will be generated and overwrite the existing key (y/n): y
        The encrypted file /Users/chang/.loaddump/secure/secure.rsa has been generated for sensitive information.

        ```
 5. 验证密钥对与加密文件是否生成成功。

   ```shell
   $ ls ~/.loaddump/secure/
   key.pem     key.pem.pub    secure.rsa

   ```
 6. 在 `{ob-loader-dumper}/conf/decrypt.properties` 中填写加密后的信息。

   ```shell
   # Absolute path of your secure file, whose name is secure.rsa by default.
   # secure.filePath=

   # Absolute path of your private key. whose name is key.pem by default.
   # privateKey.filePath=

   # Decrypt class name. Fill in this field only if you need a custom mechanism of decryption.
   # decrypt.className=

   ```

### 查看 secure-gen 帮助

secure-gen 为 Shell 可执行脚本，可以通过 RSA 算法加密敏感信息字段。运行导数工具时，会通过解析 `{ob-loader-dumper}/conf/decrypt.properties` 文件，安全地获取敏感信息。

secure-gen 在 `{ob-loader-dumper}/tools/` 目录下，可执行 `./secure-gen -h` 或直接输入 `./secure-gen` 查看使用帮助。

```shell
$ ./secure-gen -h

Usage: ./secure-gen [-n <file>][-i][-h]
Description:
-n: Specify a to-be-encrypted file of sensitive contents in plain-text, use -i to check out the format.
-i: Input sensitive contents in interactive mode.
-h: Display this message.

```

## 高级用法：自定义加解密机制

如果未安装 `openssl`，可以通过此方法自定义加密和解密。

1. 创建明文文件加密。

   待加密的文件格式需符合 Property File Format 规范。具体请参考 [Oracle 文件格式](https://docs.oracle.com/cd/E23095_01/Platform.93/ATGProgGuide/html/s0204propertiesfileformat01.html)。
 2. 使用 Java 编写一个解密类的文件。类的定义如下：

      - 必须定义无参构造函数。
      - 拥有非静态方法：`public String decrypt(String encryptRaw)`。形参 `encryptRaw` 为加密后的文本，返回值为解密后的文本。
 3. 将解密类打包成 JAR 包并放置在 `{ob-loader-dumper}/lib/` 路径下。
 4. 在 `{ob-loader-dumper}/conf/decrypt.properties` 配置相应的内容。

### 操作示例

新建一个 Maven 项目并编写一个 `CustomDecryptor` 类，使用 Base64 算法进行编解码。

#### 说明

在生产环境中，用户可以根据需求使用合适的加解密算法。

1. 创建明文加密文件，通过 Base64 进行编码。

   ```shell
   # 创建明文文件
   $ vi password.txt
   # 输入以下内容并保存退出
   oceanbase.jdbc.password=******
   oceanbase.jdbc.sys.password=******

   # 将编码后的文本保存至 custom.key 文件, 即加密文件。
   $ echo $(base64 password.txt) > /user/loaddump/custom.key

   ```
 2. 新建一个 Java 项目。项目结构中，`CustomDecryptor.java` 是需要编写的自定义解密类。

    ![customdecryptor](https://obbusiness-private.oss-cn-shanghai.aliyuncs.com/doc/img/obloaderobdumper/420/encryption.png)
 3. 编写 `CustomDecryptor` 类。

   ```shell
   package com.example.decrypt;

   import java.nio.charset.StandardCharsets;
   import sun.misc.BASE64Decoder;

   public class CustomDecryptor {

      public CustomDecryptor() {}

       /**
       * This method takes an encrypted string, decrypt it, and return it as a plain string.
       */
      public String decrypt(String encryptedRaw) throws Exception {
          BASE64Decoder decoder = new BASE64Decoder();
          return new String(decoder.decodeBuffer(encryptedRaw), StandardCharsets.UTF_8);
     }
   }

   ```
 4. 将 `CustomDecryptor` 类打包成 JAR 并放置在 `{ob-loader-dumper}/lib/` 路径下，完成设置解密器。

   ```shell
   mvn package && mv target/example-1.0-SNAPSHOT.jar path/to/ob-loader-dumper/lib/

   ```
 5. 在 `{ob-loader-dumper}/conf/decrypt.properties` 中填写相应的内容。

   ```shell
   # Absolute path of your secure file, whose name is secure.rsa by default.
   secure.filePath=～/tmp/custom.key
   # Absolute path of your private key. whose name is key.pem by default.
   # privateKey.filePath=
   # Decrypt class name. Fill in this field only if you need a custom mechanism of decryption.
   decrypt.className=com.example.decrypt.CustomDecryptor

   ```

   #### 说明

   使用自定义 SDK 加密和解密时，可以不填写 `privateKey.filePath` 的参数值。
 6. 安全地运行导数工具。

   ```shell
   ./obdumper -hxx.x.x.x -P2883 -t example -D example --csv --all

   ```

   #### 说明

   运行导数工具时，无需显式声明 `-p`/`--password` 和 `--sys-password` 选项。

## 通过 SSL 协议连接数据库

导数工具 V4.3.1 及之后版本，支持通过 SSL 协议连接数据库。下文为您介绍通过 SSL 协议连接数据库的两种方案。

### 方案一：通过配置 SSL 相关参数来启用 SSL 连接

在 `session.config.json` 文件中配置 SSL 相关参数。`session.config.json` 文件的详情请参见 [连接配置](https://www.oceanbase.com/docs/common-oceanbase-dumper-loader-1000000002401637)。

```shell
"useSSL": true,
"disableSslHostnameVerification": true,
"trustStore": "http://xxx.xxx.xxx.xxx:39411/rpcssl/truststore.jks",
"trustStorePassword": "123xxxx",
"//keyStore": "xxxxx",
"//keyStorePassword": ""

```

请根据实际情况配置 `trustStore` 和 `trustStorePassword`。

- `trustStore` 可以是 HTTP 指定的路径，也可以是本地路径。例如，`"trustStore": "/home/admin/downloads/truststore.jks"`。
 - `trustStorePassword` 配置的是明文密码，请注意此处并非数据库密码。

### 方案二：使用 secure-gen 加密

您也可以使用 secure-gen 加密方案连接数据库，以提升安全性，减少安全风险。示例如下：

1. 安装 [OpenSSL](https://www.openssl.org/source/?spm=a2c4g.42216.0.0.7097553fHQEFiE) 并配置环境变量。
 2. 在 `{ob-loader-dumper}/tools/` 目录下执行以下命令。

   ```
 3. 在交互窗口中输入相关的密码参数，完成后请输入 `:wq` 保存并退出。

   ```shell
   # Input the sensitive fields below in plain-text respectively.
   # Note ob-loader-dumper will parse from cli args first, and override any field in this file if there is a conflict.
   #
   # This password used for creating JDBC Connection.
   oceanbase.jdbc.password=*******
   # This password used for creating JDBC Connection of sys tenant.
   oceanbase.jdbc.sys.password=******
   # Trust store password for creating JDBC Connection with useSSL=true.
   oceanbase.jdbc.trustStorePassword=******
   # Key store password for creating JDBC Connection with useSSL=true (×509).
   # oceanbase.jdbc.keyStorePassword=
   # AccessKey for cloud storages like OSS, S3.
   # cloud.storage.access. key=
   # SecretKey for cloud storages like

   ```
 4. 默认会使用 OpenSSL 在本地生成加密文件和秘钥，然后将加密文件（secure.rsa）和秘钥（key.pem）添加到 `conf/security.properties`。

   您也可以将加密文件和秘钥分别放在不同的 HTTP 服务器上，程序启动时自动加载加密文件和秘钥并解密信息。

 上一篇 下一篇 ![有帮助](https://gw.alipayobjects.com/mdn/ob_asset/afts/img/A*y6ocSqN8cqsAAAAAAAAAAAAAARQnAQ)![无帮助](https://gw.alipayobjects.com/mdn/ob_asset/afts/img/A*BG9IQJyLHF8AAAAAAAAAAAAAARQnAQ)![反馈](https://gw.alipayobjects.com/mdn/ob_asset/afts/img/A*eTWdQKCRKHwAAAAAAAAAAAAAARQnAQ)[AI](https://www.oceanbase.com/obi) 咨询热线
