# rsa **Repository Path**: li-aogui/rsa ## Basic Information - **Project Name**: rsa - **Description**: 本项目提供了一套完整的 RSA 密码学操作接口,可用于确保数据的安全性和完整性。默认使用2048位密钥长度,提供更高的安全性。 - **Primary Language**: Java - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 1 - **Created**: 2024-08-27 - **Last Updated**: 2025-01-17 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # RSA 加解密工具 #### 项目介绍 这是一个用于 RSA 加密、解密、数字签名和验签的工具库。本项目提供了一套完整的 RSA 密码学操作接口,可用于确保数据的安全性和完整性。默认使用2048位密钥长度,提供更高的安全性。 #### 主要功能 - RSA 密钥对生成(2048位) - 数据加密和解密 - 数字签名生成 - 签名验证 #### 环境要求 - JDK 1.8 或以上 - Maven 3.0+ #### 安装使用 1. 克隆项目到本地 ```bash git clone [项目地址] ``` 2. 添加 Maven 依赖 ```xml com.test rsa-utils 1.0.0 ``` 3. 构建项目 ```bash mvn clean install ``` #### 使用示例 ```java // 生成密钥对(2048位) KeyPair keyPair = RSAUtils.generateKeyPair(); PublicKey publicKey = keyPair.getPublic(); PrivateKey privateKey = keyPair.getPrivate(); // 加密 String plainText = "Hello World"; byte[] encrypted = RSAUtils.encrypt(plainText.getBytes(), publicKey); // 解密 byte[] decrypted = RSAUtils.decrypt(encrypted, privateKey); // 签名 byte[] signature = RSAUtils.sign(plainText.getBytes(), privateKey); // 验签 boolean isValid = RSAUtils.verify(plainText.getBytes(), signature, publicKey); ``` #### 注意事项 - 密钥安全:请妥善保管私钥,避免泄露 - 性能考虑:RSA 不适合加密大量数据,建议仅用于加密密钥等小数据量场景 - 密钥长度:使用2048位密钥长度,单次加密最大支持245字节,解密最大支持256字节 - 分块处理:大数据量加密时会自动进行分块处理 #### 常见问题 1. 密钥格式问题:支持 PKCS8(私钥)和 X509(公钥)编码格式 2. 加密数据长度限制: - 加密块大小:245字节(2048位密钥)计算公式:2048/8-11=245 - 解密块大小:256字节(2048位密钥)计算公式:2048/8=256 3. 性能优化建议: - 大文件加密建议使用对称加密 - RSA适合加密密钥等小数据量场景 #### 贡献指南 1. Fork 本仓库 2. 新建分支: `git checkout -b feature/your-feature-name` 3. 提交改动: `git commit -am '添加新特性'` 4. 推送分支: `git push origin feature/your-feature-name` 5. 提交 Pull Request #### 开源协议 本项目采用 MIT 协议开源,详见 LICENSE 文件。 #### 问题反馈 - 提交 Issue - Pull Request - 邮件联系: [维护者邮箱]