跳到主要内容

密钥生成

要检查桌面应用是否支持加密,请调用以下命令:

typeof window.AscDesktopEditor.cloudCryptoCommand === "function";

以下步骤解释了 ONLYOFFICE 中的文档加密过程。

  1. 登录到云端并传递加密插件 ID:

    window.AscDesktopEditor.execCommand("portal:login", JSON.stringify({
    encryptionKeys: {
    cryptoEngineId: "{FFF0E1EB-13DB-4678-B67D-FF0A41DBBCEF}",
    },
    }));
  2. 要监控登录页面的密码,请通过 execCommand 方法向桌面编辑器发送 portal:checkpwd 命令。参数以带有序列化 json 的字符串格式指定,如下所示:

    {
    "domain": "域名",
    "emailInput": "user@email.addr",
    "pwdInput": "密码"
    }
    名称类型示例描述
    domainstring"https://exampledomain.com"定义云端名称和云端入口点。
    emailInputstring"john@example.com"定义在登录页面上输入的用户电子邮件。
    pwdInputstring"123456"定义在登录页面上输入的密码。

    示例

    window.AscDesktopEditor.execCommand("portal:checkpwd", JSON.stringify({
    domain: "https://exampledomain.com",
    emailInput: "john@example.com",
    pwdInput: "123456",
    }));

    发送命令后,DMS 提供商将登录页面的密码信息传输到桌面应用。ONLYOFFICE 桌面编辑器会记住该密码,并将其用于密钥的加密和解密。

  3. 使用以下参数将来自 DMS 提供商的加密私钥、公钥以及登录信息传递给桌面应用:

    {
    "encryptionKeys": {
    "cryptoEngineId": "guid",
    "privateKeyEnc": "私钥",
    "publicKey": "公钥"
    }
    }
    名称类型示例描述
    cryptoEngineIdstring"{FFF0E1EB-13DB-4678-B67D-FF0A41DBBCEF}"定义加密插件 ID。
    privateKeyEncstring"xxx"定义加密的私钥。
    publicKeystring"yyy"定义公钥。

    示例

    window.AscDesktopEditor.execCommand("portal:login", JSON.stringify({
    encryptionKeys: {
    cryptoEngineId: "{FFF0E1EB-13DB-4678-B67D-FF0A41DBBCEF}",
    privateKeyEnc: "xxx",
    publicKey: "yyy",
    },
    }));

    你也可以在编辑器初始化配置中进行设置:

    const config = {
    editorConfig: {
    encryptionKeys: {
    cryptoEngineId: "{FFF0E1EB-13DB-4678-B67D-FF0A41DBBCEF}",
    privateKeyEnc: "xxx",
    publicKey: "yyy",
    },
    },
    };

    const docEditor = new DocsAPI.DocEditor("placeholder", config);
  4. 通过带有 encryptionKeys 类型的 cloudCryptoCommand 方法将生成的密钥发送到云端:

    window.AscDesktopEditor.cloudCryptoCommand(
    "encryptionKeys",
    {
    cryptoEngineId: "{FFF0E1EB-13DB-4678-B67D-FF0A41DBBCEF}",
    privateKeyEnc: "xxx",
    publicKey: "yyy",
    },
    callback,
    );