RSAPublicKey中有两个方法getModulus()对应公钥的模数;
getPublicExponent()对应公钥的指数;
当但这两个值都是BigInteger类型,需要转成String类型;
引入maven依赖包:
<dependency>
<groupId>com.nimbusds</groupId>
<artifactId>nimbus-jose-jwt</artifactId>
<version>8.20</version>
</dependency>
源代码如下:
String pukModule = org.apache.commons.codec.binary.Base64
.encodeBase64URLSafeString(BigIntegerUtils.toBytesUnsigned(publicKey.getModulus()));
String pukPubExp = org.apache.commons.codec.binary.Base64
.encodeBase64URLSafeString(BigIntegerUtils.toBytesUnsigned(publicKey.getPublicExponent()));