更新时间:2023-01-31 19:00:02
解决方案:将 BEGIN RSA PRIVATE KEY
更改为 BEGIN PRIVATE KEY
Solution: Change BEGIN RSA PRIVATE KEY
with BEGIN PRIVATE KEY
Java 以 PKCS#8 格式对密钥进行编码
Java encodes the key IN PKCS#8 format
PrivateKey privateKey = keyFactory.generatePrivate(new PKCS8EncodedKeySpec(privateKeyGenerated.getEncoded()));
但是您正在生成一个带有标题 -----BEGIN RSA PRIVATE KEY-----
的 PEM 文件,该文件保留给 PKCS#1 密钥(旧格式但很常见),并且 .onion 假设它是 pkcs1,而实际上它是 pkcs8.查看错误
But you are generating a PEM file with the header -----BEGIN RSA PRIVATE KEY-----
which is reserved to PKCS#1 keys (old format but very common), and .onion is assuming that it is pkcs1 when it really is pkcs8. See the error
TLS error: RSA lib (in rsa routines:OLD_RSA_PRIV_DECODE:---)
所以你需要使用PCKS#8头-----BEGIN PRIVATE KEY-----
So you need to use the PCKS#8 header -----BEGIN PRIVATE KEY-----