> For the complete documentation index, see [llms.txt](https://alien-3.gitbook.io/alien/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://alien-3.gitbook.io/alien/alien-an-quan-jia-gou/lian-shang-jia-mi.md).

# 链上加密

链上加密利用区块链技术记录和验证消息的传输和存储过程，确保数据的不可篡改性和透明性。

* 区块链记录： 每条消息的哈希值和元数据都将（如时间戳、发送者和接收者的身份）记录在区块链上，形成不可篡改的日志。
* 智能合约： 使用智能合约管理和验证数据传输过程，确保数据的完整性和真实性。

// 示例：链上记录

import { ethers } from 'ethers';

const provider = new ethers.providers.JsonRpcProvider('<http://localhost:8545>');

const contractAddress = '0xYourContractAddress';

const abi = \[

&#x20; // 合约ABI

];

const contract = new ethers.Contract(contractAddress, abi, provider);

<br>

// 存储消息哈希

async function storeMessageHash(hash) {

&#x20; const signer = provider.getSigner();

&#x20; const tx = await contract.connect(signer).storeMessageHash(hash);

&#x20; await tx.wait();

&#x20; console.log('Message hash stored on blockchain');

}
