- 生成私钥(默认为 pkcs1 格式)
openssl genrsa -out access_token_private_key.pem 2048
生成结果:
-----BEGIN RSA PRIVATE KEY-----
MIIEowIBAAKCAQEAv39BQVAS4E5IxwJIMc5/+gc0pVkCqkR4evDUiIA56onrI/6o
P6B88DuO+wCyz5LjK1thHOVTWbWjDbBMc41kGYxBRddeggY75B+x6Pcl7s7UavCk
9pWFRIotOAtSoeDc21zmPm8id/CsvfXyUzb89873BdJ0GnJ5QTSKAVY2XUZp83ax
xIbQpAm03PydZBujDjzSZkFfJKdkLKhzfqB1FReBatjtiP5PubYkzr9oxcxqsaln
Rl6TGjtER+VKqAeHxstzRb+eIQR1QIzqE82vkBxpYthfHpL3tbEg29+Zq37Mn0TB
boxM6hbTfd6zDp+YVBDU5yK95BRFzn9ib/xsjQIDAQABAoIBAD3jJnexJSiQpDyM
pEBUeE+ZnI4DYjUcw8MXqdgjeJQv1mpflohZmYcZ+G9uHluvIPOWKKBqDLHlXbjC
zTJa84q+JSopHEXxNdHX3Gtp1DyFY2jcNLPsRpGMBmkiX6YpQbczIsXyrLUOdwU9
Qv9Zug9sN7EN/q+9ZyqHjEI6Vn91/wiF9tv0AjySiq9r/uXY5uuIbFVjO2tOkPWd
4QkPJM3wISorqCrVmhKTAEXU9WWhOUPrxGv8lK8Rw8nHVBDeeOUKte6ksWFCvNJm
+OeFByHfC5UG2jDdx/20PYEuBXlcSnDZ+NPLxqq0FyrbGvtNtGKk9RqskZPIe++t
apdcigECgYEA4sexnesnjP/H04m4wFh78/4CzuWhewrrh2w+xLQjEVCLC3ju+mUy
k5c+KCc8EgYTqq1t3HeO60i8mVTVGUicFDwYZwoM5Wxd+ca60Yt9VnTr5MBSNo9l
cz08BiKREdfrDtWlBkWAx0ZFWJumCyaDKv4mpvEFpg+kgWUHHqIkcO0CgYEA2CvB
/aJqKg8MLNH/9J3gmvIQ0r8L47s9I+q7HcLlpxpOS/OYmdw4XFsq1phEyVl7v7Zt
0cjy8OyKMDNgSEl81covN3CCnY8hmSW/M0lwUnKTUqSGdT3n71+B4LCPxIKS3532
DzcbWal9bfB004kNM45eUDIkGbYMqIN24jq7liECgYEA28+ZjqrWzClEY/ry06Uw
iB/mUupq6dt8zeeSs5CzCN5b18PhR1z9d+c5/SuCYyn2uBGgEfjk05POEoUShI5H
kqlpMb6hH2M5d5gzjlY5J6ru1uu/BFlbiSaKXpv0pyn1EYzthrWpi/3Fy4walmY+
71Ym2tt1kS9KUY0+KGgbEEUCgYByquOAc0L1hH3k2JB5ZbXa+0TJReY8qvnHr6AK
LXQ8q8uUpmbwVsze0M1sf+EdHYZzL4YZngqgmhjDcL1GGxVJIrLhKaFfiqk737YI
spAObBCR6gwY7Pm3FGaElaPtjYXzcIsxjv3HFg0e4EpYW37RNlf5Gl/j85nLWdEa
OCWBgQKBgHIZx/4U3zc6tTQf7+NeOn2uxA1S+Pra1EMur3jJoU+4rsT74RBNSF2B
Pc7EfC/SVWUhzAahpvbY7RJenza3EnW7vOPupjU4/7LXDYw12P89JVDDrSS2BFZG
C2Rl6EojESpLg8dlx/drnEjHOzMwj15/I+5kCWuItQ1ryAIteamz
-----END RSA PRIVATE KEY-----
- 根据私钥生成公钥
openssl rsa -in access_token_private_key.pem -pubout -out access_token_public_key.pem
生成结果:
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAv39BQVAS4E5IxwJIMc5/
+gc0pVkCqkR4evDUiIA56onrI/6oP6B88DuO+wCyz5LjK1thHOVTWbWjDbBMc41k
GYxBRddeggY75B+x6Pcl7s7UavCk9pWFRIotOAtSoeDc21zmPm8id/CsvfXyUzb8
9873BdJ0GnJ5QTSKAVY2XUZp83axxIbQpAm03PydZBujDjzSZkFfJKdkLKhzfqB1
FReBatjtiP5PubYkzr9oxcxqsalnRl6TGjtER+VKqAeHxstzRb+eIQR1QIzqE82v
kBxpYthfHpL3tbEg29+Zq37Mn0TBboxM6hbTfd6zDp+YVBDU5yK95BRFzn9ib/xs
jQIDAQAB
-----END PUBLIC KEY-----
- 将私钥的 pkcs1 转换成 pkcs8 格式,使用 -nocrypt 表示不使用密码(否则需要在命令行输入密码)
openssl pkcs8 -in access_token_private_key.pem -topk8 -out access_token_pkcs8_private_key.pem -nocrypt
生成结果:
-----BEGIN PRIVATE KEY-----
MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQC/f0FBUBLgTkjH
Akgxzn/6BzSlWQKqRHh68NSIgDnqiesj/qg/oHzwO477ALLPkuMrW2Ec5VNZtaMN
sExzjWQZjEFF116CBjvkH7Ho9yXuztRq8KT2lYVEii04C1Kh4NzbXOY+byJ38Ky9
9fJTNvz3zvcF0nQacnlBNIoBVjZdRmnzdrHEhtCkCbTc/J1kG6MOPNJmQV8kp2Qs
qHN+oHUVF4Fq2O2I/k+5tiTOv2jFzGqxqWdGXpMaO0RH5UqoB4fGy3NFv54hBHVA
jOoTza+QHGli2F8ekve1sSDb35mrfsyfRMFujEzqFtN93rMOn5hUENTnIr3kFEXO
f2Jv/GyNAgMBAAECggEAPeMmd7ElKJCkPIykQFR4T5mcjgNiNRzDwxep2CN4lC/W
al+WiFmZhxn4b24eW68g85YooGoMseVduMLNMlrzir4lKikcRfE10dfca2nUPIVj
aNw0s+xGkYwGaSJfpilBtzMixfKstQ53BT1C/1m6D2w3sQ3+r71nKoeMQjpWf3X/
CIX22/QCPJKKr2v+5djm64hsVWM7a06Q9Z3hCQ8kzfAhKiuoKtWaEpMARdT1ZaE5
Q+vEa/yUrxHDycdUEN545Qq17qSxYUK80mb454UHId8LlQbaMN3H/bQ9gS4FeVxK
cNn408vGqrQXKtsa+020YqT1GqyRk8h7761ql1yKAQKBgQDix7Gd6yeM/8fTibjA
WHvz/gLO5aF7CuuHbD7EtCMRUIsLeO76ZTKTlz4oJzwSBhOqrW3cd47rSLyZVNUZ
SJwUPBhnCgzlbF35xrrRi31WdOvkwFI2j2VzPTwGIpER1+sO1aUGRYDHRkVYm6YL
JoMq/iam8QWmD6SBZQceoiRw7QKBgQDYK8H9omoqDwws0f/0neCa8hDSvwvjuz0j
6rsdwuWnGk5L85iZ3DhcWyrWmETJWXu/tm3RyPLw7IowM2BISXzVyi83cIKdjyGZ
Jb8zSXBScpNSpIZ1PefvX4HgsI/EgpLfnfYPNxtZqX1t8HTTiQ0zjl5QMiQZtgyo
g3biOruWIQKBgQDbz5mOqtbMKURj+vLTpTCIH+ZS6mrp23zN55KzkLMI3lvXw+FH
XP135zn9K4JjKfa4EaAR+OTTk84ShRKEjkeSqWkxvqEfYzl3mDOOVjknqu7W678E
WVuJJopem/SnKfURjO2GtamL/cXLjBqWZj7vViba23WRL0pRjT4oaBsQRQKBgHKq
44BzQvWEfeTYkHlltdr7RMlF5jyq+cevoAotdDyry5SmZvBWzN7QzWx/4R0dhnMv
hhmeCqCaGMNwvUYbFUkisuEpoV+KqTvftgiykA5sEJHqDBjs+bcUZoSVo+2NhfNw
izGO/ccWDR7gSlhbftE2V/kaX+PzmctZ0Ro4JYGBAoGAchnH/hTfNzq1NB/v4146
fa7EDVL4+trUQy6veMmhT7iuxPvhEE1IXYE9zsR8L9JVZSHMBqGm9tjtEl6fNrcS
dbu84+6mNTj/stcNjDXY/z0lUMOtJLYEVkYLZGXoSiMRKkuDx2XH92ucSMc7MzCP
Xn8j7mQJa4i1DWvIAi15qbM=
-----END PRIVATE KEY-----
- 根据 pkcs8 格式的私钥生成公钥 - 发现和根据 pkcs1 格式生成的公钥内容相同
openssl rsa -in access_token_pkcs8_private_key.pem -pubout -out access_token_pkcs8_public_key.pem
生成结果:
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAv39BQVAS4E5IxwJIMc5/
+gc0pVkCqkR4evDUiIA56onrI/6oP6B88DuO+wCyz5LjK1thHOVTWbWjDbBMc41k
GYxBRddeggY75B+x6Pcl7s7UavCk9pWFRIotOAtSoeDc21zmPm8id/CsvfXyUzb8
9873BdJ0GnJ5QTSKAVY2XUZp83axxIbQpAm03PydZBujDjzSZkFfJKdkLKhzfqB1
FReBatjtiP5PubYkzr9oxcxqsalnRl6TGjtER+VKqAeHxstzRb+eIQR1QIzqE82v
kBxpYthfHpL3tbEg29+Zq37Mn0TBboxM6hbTfd6zDp+YVBDU5yK95BRFzn9ib/xs
jQIDAQAB
-----END PUBLIC KEY-----
网友评论