如何在RSA公钥RSAPublicKey中获取指数和模

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()));

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容