- RSA密钥生成过程:
- 选择两个大质数 p 和 q (例如 p=3, q=11)
- 计算 N = p * q (N = 3 * 11 = 33)
- 计算欧拉函数 φ(N) = (p-1) * (q-1) (φ(33) = 2 * 10 = 20)
- 选择公钥 E,满足 1 < E < φ(N),且 E 与 φ(N) 互质 (例如 E = 3)
- 计算私钥 D,满足 (D * E) mod φ(N) = 1 (D = 7)
- 加密过程: 密文 = 明文^E mod N
- 解密过程: 明文 = 密文^D mod N
- 安全性: RSA的安全性基于大数分解的困难性。即使知道 N 和 E,在 N 非常大时,很难在合理时间内分解出 p 和 q。
- 公钥与私钥:
- 公钥(E, N)用于加密,可以公开
- 私钥(D, N)用于解密,必须保密


具体来说:
非对称加密(直接在数据库中查固定密钥) genPubicKey
前端使用base64编码 + 公钥加密
解密流程:
- Base64解码:接收到的加密字符串先通过
Base64.decodeBase64进行解码,转换为字节数组。 - RSA解密:通过
Cipher实例,使用RSA/ECB/PKCS1Padding加密模式和 RSA 私钥来解密数据。








Excellent explanation of RSA encryption! The key generation process demonstration makes the mathematical foundation crystal clear. For platforms handling sensitive user data like 56jl ph, implementing proper RSA/ECB/PKCS1Padding encryption is crucial for secure authentication.