注意:以下翻译的准确性尚未经过验证。这是使用 AIP ↗ 从原始英文文本进行的机器翻译。

在函数和操作中使用CipherText属性

在函数中使用Cipher需要一个操作用户许可证。如果为此操作(哈希、加密、解密)配置了检查点,则许可证必须被允许绕过检查点

函数代码库可以被用于在与CipherText对象属性交互,从而实现复杂的逻辑,如批量加密或批量解密。要开始使用函数,请参见本教程

对于下面的例子,假设我们有一个EncryptedCustomer对象,具有以下属性:

  • 一个加密的CipherText name
  • 一个唯一的、未加密的整数id

我们将编写两个函数与此对象交互:

  • decryptEncryptedCustomer()将接收一个EncryptedCustomer对象并返回明文名称。
  • updateEncryptedName()将接收一个EncryptedCustomer对象和一个newName,并将该对象的加密名称更新为newName

Type_Classes

在函数中解密CipherText属性

在此示例中,我们解密并返回EncryptedCustomer对象的name属性。

// 从 "@foundry/functions-api" 导入所需模块
import { Function, Integer, OntologyEditFunction, Edits } from "@foundry/functions-api";

// 从 "@foundry/ontology-api" 导入所需模块
import { Objects, EncryptedCustomers } from "@foundry/ontology-api";

// 定义一个函数装饰器
@Function()
public async decryptEncryptedCustomer(customer: EncryptedCustomers): Promise<string | undefined> {
    // 异步解密客户的名字并返回结果,如果名字不存在则返回 undefined
    return await customer.name?.decryptAsync();
}

更新函数中的CipherText属性

在下面的示例中,我们更新了EncryptedCustomer对象的name属性。请注意,本示例中的函数与任何更新对象的函数一样,必须使用@OntologyEditFunction()@Edits(EncryptedCustomers)进行注解。另外请注意,在预览中运行此函数实际上不会编辑该对象。

Copied!
1 2 3 4 5 6 7 8 9 10 11 import { Function, Integer, OntologyEditFunction, Edits } from "@foundry/functions-api"; import { Objects, EncryptedCustomers } from "@foundry/ontology-api"; // 使用装饰器定义一个本体编辑函数 @OntologyEditFunction() // 指定该函数会编辑 EncryptedCustomers 对象 @Edits(EncryptedCustomers) public async updateEncryptedName(customer: EncryptedCustomers, newName: string): Promise<void> { // 异步更新客户的加密名称为 newName await customer.name?.updateAsync(newName); }