CodeToolProCodeToolPro
GitHub

RSA Key Pair Generator

Generate RSA Key Pair

  • 技术详情

    RSA 密钥生成器的工作原理

    工具功能

    RSA 密钥生成器可生成非对称加密所需的 RSA 公钥-私钥对,输出 PEM 格式的密钥文件。支持选择密钥长度(如 2048、3072、4096 位),并可选地使用密码短语(passphrase)加密私钥以增强安全性。RSA 是目前最广泛使用的非对称加密算法之一,广泛用于 SSL/TLS 证书、SSH 密钥和数字签名场景。


    常见开发者使用场景

    RSA 密钥对在安全和身份验证中无处不在:生成 SSH 密钥对用于服务器 Git 仓库的免密登录、创建 SSL/TLS 证书的密钥对用于 HTTPS 服务、在 JWT 认证中使用 RS256 算法签名 Token、以及实现端到端加密消息系统。后端开发者部署微服务时通常为每个服务生成唯一的密钥对。

    生成的密钥可与 JWT 解码器 配合验证 RS256 签名的 Token。证书解码器 可解析使用 RSA 密钥签署的证书。Base64 编解码器 可处理 PEM 格式的 Base64 内容。Bcrypt 生成器 处理的是密码哈希,不同于 RSA 的非对称加密。


    技术原理/相关概念

    RSA 基于大整数分解难题:生成两个大素数 p 和 q,计算 n = p × q 和欧拉函数 φ(n) = (p-1)(q-1)。选择公钥指数 e(通常为 65537),计算密钥指数 d 使得 d × e ≡ 1 (mod φ(n))。公钥为 (n, e),私钥为 (n, d)。加密时 c = mᵉ mod n,解密时 m = cᵈ mod n。密钥越长(位数越大),n 越大,因数分解越困难,安全性越高。


    常见陷阱与注意事项

    • 密钥长度:2048 位是目前的最低安全标准,3072 位确保中长期安全,4096 位更安全但操作速度更慢。
    • 私钥保护:私钥永远不应传输或分享。使用密码短语(passphrase)加密私钥文件以在存储层面提供额外保护。
    • 浏览器环境:浏览器中的密钥生成受限于 Crypto API 的支持,生成大密钥可能耗时较长。
    • PEM 格式:正确区分公钥(-----BEGIN PUBLIC KEY-----)和私钥(-----BEGIN RSA PRIVATE KEY-----)格式,不要混淆使用。

    何时使用此工具而非代码

    在快速生成测试用密钥对、为演示项目或开发环境配置密钥时使用此工具。适合一次性的密钥生成需求。对于生产环境,推荐使用 OpenSSL 命令行工具(openssl genrsa / openssl rsa)或编程语言的密钥生成库(如 Node.js 的 crypto.generateKeyPair、Python 的 cryptography.hazmat.primitives),它们提供更好的随机数生成器、更全面的密钥管理和格式支持。

    How to Use RSA Key Pair Generator

    1. 1Configure your generation settings (length, format, options)
    2. 2Click the Generate button to create new output
    3. 3Review the generated result
    4. 4Copy the output to your clipboard or download it

    Frequently Asked Questions

    • Can I use the generated output in production?

      Yes, all generated values are cryptographically random (where applicable) and ready for production use. No special attribution required.

    • Is RSA Key Pair Generator free?

      Yes, 100% free. No registration, no credit card required. All tools are freely available for developers worldwide.

    • Does this tool upload my data to any server?

      No. All processing runs locally in your browser using client-side JavaScript. Your input data, code, or files never leave your device. We do not store, log, or transmit any user data.