1.keytoo工具生成jks证书
keytool在jdk/bin目录下
在idea terminal使用 keytool生成jks:
idea——terminal
跳到指定要生成jks目录:
/home/echo/IdeaProjects/spring-security-oauth2-demo/spring-security-oauth2-authorization-jwt/src/main/resources
生成jks指令:
keytool -genkeypair -alias oauth2 -keyalg RSA -keystore oauth2.jks -keysize 2048
#oauth2 为自定义,oauth2.jks为证书名称,可指定路径,不指定当前目录下
下面就是生成公钥:
keytool -list -rfc --keystore oauth2.jks | openssl x509 -inform pem -pubkey
'openssl' 不是内部或外部命令,也不是可运行的程序
或批处理文件
2.下载openssl,并安装配置
下载地址:openssl
随便下载一个好了,反正都是exe的,至于收费那是不可能的(土豪随意)。
安装完成之后配置一下环境变量。把openssl安装路径bin的路径(例如 D:\OpenSSL-Win64\bin)加入到操作系统的系统环境变量Path中。
重启电脑!!!
用管理员身份运行DOS就可以进行openssl的操作了。
解决openssl错误
WARNING: can't open config file: /usr/local/ssl/openssl.cnf
在你得opensll安装路径下找到openssl.cfg,我的路径是 D:\OpenSSL-Win64\bin\openssl.cfg,设置环境变量
set OPENSSL_CONF=D:\OpenSSL-Win64\bin\openssl.cfg
下面就是生成公钥:
D:\...\resources>keytool -list -rfc --keystore oauth2.jks | openssl x509 -inform pem -pubkey
'openssl' 不是内部或外部命令,也不是可运行的程序
或批处理文件。
D:\...\resources>keytool -list -rfc --keystore oauth2.jks | D:\OpenSSL-Win64\bin\openssl x509 -inform pem -pubkey
WARNING: can't open config file: /usr/local/ssl/openssl.cnf
unable to load certificate
10728:error:0906D06C:PEM routines:PEM_read_bio:no start line:.\crypto\pem\pem_lib.c:697:Expecting: TRUSTED CERTIFICATE
D:\...\resources>set OPENSSL_CONF=D:\OpenSSL-Win64\bin\openssl.cfg
D:\...\resources>keytool -list -rfc --keystore oauth2.jks | D:\OpenSSL-Win64\bin\openssl x509 -inform pem -pubkey
输入密钥库口令: 123456
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBC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