naveena-zen/Blockchain-Certificate-Verify

GitHub: naveena-zen/Blockchain-Certificate-Verify

基于区块链的证书发行与验证系统,解决凭证防篡改与跨机构可信验证问题。

Stars: 0 | Forks: 0

# CertChain PRO **基于区块链的证书验证** — 使用以太坊智能合约、IPFS去中心化存储和RSA加密签名实现防篡改的凭证发行与验证。 ![Python](https://img.shields.io/badge/Python-3.8+-3776AB?style=flat-square&logo=python&logoColor=white) ![Ethereum](https://img.shields.io/badge/Ethereum-Sepolia-627EEA?style=flat-square&logo=ethereum&logoColor=white) ![IPFS](https://img.shields.io/badge/Storage-IPFS-65C2CB?style=flat-square&logo=ipfs&logoColor=white) ![Streamlit](https://img.shields.io/badge/UI-Streamlit-FF4B4B?style=flat-square&logo=streamlit&logoColor=white) ## 功能特性 | 功能特性 | 描述 | |---|---| | SHA-256哈希 | 每个证书生成唯一的加密指纹 — 任何篡改均可即时检测 | | 链上验证 | 哈希通过Solidity智能合约永久存储在以太坊上 | | IPFS存储 | 完整证书数据存储在IPFS — 去中心化且抗审查 | | RSA-2048签名 | 发行者身份对每个凭证进行加密绑定 | | 实时验证 | 双重检查流水线同时验证数字签名和链上记录 | ## 系统架构 ``` User → Streamlit UI → SHA-256 → RSA Sign → IPFS → Ethereum → Verification ``` ## 先决条件 - Python 3.8+ - [IPFS桌面版或CLI](https://docs.ipfs.tech/install/) - [MetaMask](https://metamask.io/) 浏览器扩展 - [Infura](https://infura.io/) 账户(用于Sepolia RPC) - [Remix IDE](https://remix.ethereum.org/)(用于合约部署) ## 安装配置 ### 1 — 安装依赖 ``` pip install streamlit web3 cryptography requests ``` ### 2 — 启动IPFS守护进程 ``` ipfs init ipfs daemon ``` 该应用连接到 `http://127.0.0.1:5001` 处的IPFS。 ### 3 — 设置MetaMask 1. 安装扩展并创建钱包 2. 切换到 **Sepolia测试网络** 3. 从 [Sepolia水龙头](https://sepoliafaucet.com/) 获取免费测试ETH ### 4 — 部署智能合约 1. 打开 [Remix IDE](https://remix.ethereum.org/) 2. 创建新的Solidity文件并粘贴下方的 `CertChain.sol` 代码 3. 使用Solidity `^0.8.0` 编译 4. 在 *Deploy & Run* 中选择 **Injected Provider – MetaMask** 5. 部署并复制 **合约地址** 和 **ABI** ### 5 — 配置 `app.py` ``` INFURA_URL = "https://sepolia.infura.io/v3/YOUR_INFURA_KEY" CONTRACT_ADDRESS = "YOUR_CONTRACT_ADDRESS" ABI = [ ... ] # paste from Remix compilation details ``` ### 6 — 运行 ``` streamlit run app.py ``` ## 工作原理 **颁发证书** 1. 用户提交姓名、注册号、课程和机构 2. 数据序列化为规范JSON并通过SHA-256哈希 3. 使用会话私钥应用RSA-2048签名 4. 完整证书记录推送到IPFS 5. 哈希通过 `storeCertificate()` 存储在以太坊上 **验证证书** 1. 用户粘贴证书哈希 2. 检索本地记录并验证RSA签名 3. 调用链上 `verifyCertificate()` 4. 两者均通过 → **✅ 有效** — 任一失败 → **❌ 无效** | 函数 | 类型 | 描述 | |---|---|---| | `storeCertificate(hash)` | `nonpayable` | 存储哈希并发出包含发行者地址的事件 | | `verifyCertificate(hash)` | `view` | 若哈希存在则返回 `true` — 无需支付Gas费 | ## 技术栈 `Streamlit` · `Python 3.8+` · `Ethereum Sepolia` · `Web3.py` · `IPFS` · `SHA-256` · `RSA-2048` · `Solidity ^0.8.0` · `Remix IDE` · `Infura` ## 使用场景 - 学术证书 — 学位、文凭、成绩单 - 专业资质 — 许可证、认证、徽章 - 政府记录 — 身份文件、许可证、证明 - 数字凭证 — Web3成就、课程完成情况 ## 注意事项 ## 后续增强 - [ ] 基于NFT的证书(ERC-721) - [ ] MetaMask钱包认证 - [ ] 多发行机构支持 - [ ] 基于角色的访问控制 - [ ] 二维码验证流程 - [ ] 证书吊销机制
标签:DApp, IPFS去中心化存储, Kubernetes, Python区块链, RSA数字签名, Sepolia, SHA-256哈希, Streamlit前端, Web3, 以太坊智能合约, 以太坊测试网, 公钥基础设施, 分布式存储, 加密验证, 区块链证书验证, 去中心化应用, 去中心化网络, 去中心化身份认证, 可信凭证, 哈希校验, 学历证书, 安全存储, 实时验证, 操作系统检测, 数字证书, 职业认证, 逆向工具, 防篡改验证