Java Key Public getPublicKey(String modulus, String exponent)

Here you can find the source of getPublicKey(String modulus, String exponent)

Description

get Public Key

License

Open Source License

Declaration

public static PublicKey getPublicKey(String modulus, String exponent) 

Method Source Code

//package com.java2s;
/**/*from   w ww .j  a v a2 s .  com*/
 *
 * Licensed Property to China UnionPay Co., Ltd.
 * 
 * (C) Copyright of China UnionPay Co., Ltd. 2010
 *     All Rights Reserved.
 *
 * 
 * Modification History:
 * =============================================================================
 *   Author         Date          Description
 *   ------------ ---------- ---------------------------------------------------
 *   xshu       2014-05-28     ??????????????
 * =============================================================================
 */

import java.math.BigInteger;
import java.security.KeyFactory;

import java.security.PublicKey;

import java.security.spec.RSAPublicKeySpec;

public class Main {
    public static PublicKey getPublicKey(String modulus, String exponent) {
        try {
            BigInteger b1 = new BigInteger(modulus);
            BigInteger b2 = new BigInteger(exponent);
            KeyFactory keyFactory = KeyFactory.getInstance("RSA", "BC");
            RSAPublicKeySpec keySpec = new RSAPublicKeySpec(b1, b2);
            return keyFactory.generatePublic(keySpec);
        } catch (Exception e) {
            throw new RuntimeException("getPublicKey error", e);
        }
    }
}

Related

  1. getPublicKey(String certPath)
  2. getPublicKey(String filename)
  3. getPublicKey(String filename)
  4. getPublicKey(String filename)
  5. getPublicKey(String key)
  6. getPublicKey(String publicKeyContents)
  7. getPublicKey(String publicKeyFile)
  8. getPublicKey(String publicKeyFilepath, String algorithm)
  9. getPublicKeyFromBytes(final String algorithm, final byte[] publicKeyBytes)