RSA根据modulus,exponent生成公钥

本文介绍了一种通过n和e值来生成RSA公钥的方法。该方法使用BigInteger类处理模数和指数,并通过RSAPublicKeySpec指定公钥参数。最后通过KeyFactory生成公钥。

// 根据n、e值还原公钥

 public static PublicKey getPublicKey(String modulus, String publicExponent)

            throws NoSuchAlgorithmException, InvalidKeySpecException {

        BigInteger bigIntModulus = new BigInteger(modulus,16);

        BigInteger bigIntPrivateExponent = new BigInteger(publicExponent,16);

        RSAPublicKeySpec keySpec = new RSAPublicKeySpec(bigIntModulus, bigIntPrivateExponent);

        KeyFactory keyFactory = KeyFactory.getInstance("RSA");
        PublicKey publicKey = keyFactory.generatePublic(keySpec);

        return publicKey;

    }
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值