码迷,mamicode.com
首页 > 编程语言 > 详细

Java生成公私钥对

时间:2015-12-21 18:06:36      阅读:183      评论:0      收藏:0      [点我收藏+]

标签:

    public static synchronized KeyPair generateRSAKeyPair(int keysize, BigInteger publicExponent) {
        try {
            keyPairGen.initialize(new RSAKeyGenParameterSpec(keysize, publicExponent), new SecureRandom());
            return keyPairGen.generateKeyPair();
        } catch (Exception var3) {
            LOGGER.error("生成模长 =" + keysize + ",指数=" + publicExponent + "的RSA密钥对失败", var3);
            return null;
        }
    }

sample:

    public static void main(String[] args) throws Exception {
        KeyPair keyp = RSAUtils.generateRSAKeyPair(1408, RSAKeyGenParameterSpec.F0);
        PrivateKey privateKey = keyp.getPrivate();
        PublicKey publicKey = keyp.getPublic();
    }

 

Java生成公私钥对

标签:

原文地址:http://www.cnblogs.com/frankyou/p/5063917.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!