Java 类java.security.spec.RSAKeyGenParameterSpec 实例源码

项目:L2jBrasil    文件:LoginController.java   
private LoginController() throws GeneralSecurityException
{
    _log.info("Loading LoginContoller...");

    _hackProtection = new HashMap<>();

    _keyPairs = new ScrambledKeyPair[10];

    KeyPairGenerator keygen = null;

    keygen = KeyPairGenerator.getInstance("RSA");
    RSAKeyGenParameterSpec spec = new RSAKeyGenParameterSpec(1024, RSAKeyGenParameterSpec.F4);
    keygen.initialize(spec);

    //generate the initial set of keys
    for (int i = 0; i < 10; i++)
    {
        _keyPairs[i] = new ScrambledKeyPair(keygen.generateKeyPair());
    }
    _log.info("Cached 10 KeyPairs for RSA communication");

    testCipher((RSAPrivateKey) _keyPairs[0]._pair.getPrivate());

    // Store keys for blowfish communication
    generateBlowFishKeys();
}
项目:ipack    文件:KeyPairGeneratorSpi.java   
public void initialize(
    AlgorithmParameterSpec params,
    SecureRandom random)
    throws InvalidAlgorithmParameterException
{
    if (!(params instanceof RSAKeyGenParameterSpec))
    {
        throw new InvalidAlgorithmParameterException("parameter object not a RSAKeyGenParameterSpec");
    }
    RSAKeyGenParameterSpec rsaParams = (RSAKeyGenParameterSpec)params;

    param = new RSAKeyGenerationParameters(
        rsaParams.getPublicExponent(),
        random, rsaParams.getKeysize(), defaultTests);

    engine.init(param);
}
项目:xitk    文件:KeyUtil.java   
public static KeyPair generateRSAKeypair(int keysize, BigInteger publicExponent,
        SecureRandom random) throws NoSuchAlgorithmException, NoSuchProviderException,
        InvalidAlgorithmParameterException {
    BigInteger tmpPublicExponent = publicExponent;
    if (tmpPublicExponent == null) {
        tmpPublicExponent = RSAKeyGenParameterSpec.F4;
    }
    AlgorithmParameterSpec params = new RSAKeyGenParameterSpec(keysize, tmpPublicExponent);
    KeyPairGenerator kpGen = getKeyPairGenerator("RSA");
    synchronized (kpGen) {
        if (random == null) {
            kpGen.initialize(params);
        } else {
            kpGen.initialize(params, random);
        }
        return kpGen.generateKeyPair();
    }
}
项目:CacheManage    文件:KeyStoreHelper.java   
@TargetApi(Build.VERSION_CODES.M)
static void createKeysM(String alias, boolean requireAuth) {
    try {
        KeyPairGenerator keyPairGenerator =
                KeyPairGenerator.getInstance(KeyProperties.KEY_ALGORITHM_RSA,
                        SecurityConstants.KEYSTORE_PROVIDER_ANDROID_KEYSTORE);
        keyPairGenerator.initialize(new KeyGenParameterSpec.Builder(alias,
                KeyProperties.PURPOSE_ENCRYPT
                        | KeyProperties.PURPOSE_DECRYPT).setAlgorithmParameterSpec(
                new RSAKeyGenParameterSpec(1024, F4))
                .setBlockModes(KeyProperties.BLOCK_MODE_CBC)
                .setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_RSA_PKCS1)
                .setDigests(KeyProperties.DIGEST_SHA256, KeyProperties.DIGEST_SHA384,
                        KeyProperties.DIGEST_SHA512)
                // Only permit the private key to be used if the user authenticated
                // within the last five minutes.
                .setUserAuthenticationRequired(requireAuth)
                .build());
        KeyPair keyPair = keyPairGenerator.generateKeyPair();
        Log.d(TAG, "Public Key is: " + keyPair.getPublic().toString());
    } catch (NoSuchProviderException | NoSuchAlgorithmException | InvalidAlgorithmParameterException e) {
        throw new RuntimeException(e);
    }
}
项目:L2J-Global    文件:GameServerTable.java   
/**
 * Inits the RSA keys.
 */
private void initRSAKeys()
{
    try
    {
        final KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");
        keyGen.initialize(new RSAKeyGenParameterSpec(512, RSAKeyGenParameterSpec.F4));
        _keyPairs = new KeyPair[KEYS_SIZE];
        for (int i = 0; i < KEYS_SIZE; i++)
        {
            _keyPairs[i] = keyGen.genKeyPair();
        }
    }
    catch (Exception e)
    {
        LOGGER.severe(GameServerTable.class.getSimpleName() + ": Error loading RSA keys for Game Server communication!");
    }
}
项目:openjdk-jdk10    文件:SpecTest.java   
public static void main(String[] args) throws Exception {

        int size = 0;

        if (args.length >= 1) {
            size = Integer.parseInt(args[0]);
        } else {
            throw new RuntimeException("Missing keysize to test with");
        }

        BigInteger publicExponent
                = (args.length >= 2) ? new BigInteger(args[1]) : RSAKeyGenParameterSpec.F4;

        System.out.println("Running test with key size: " + size
                + " and public exponent: " + publicExponent);

        KeyPairGenerator kpg1 = KeyPairGenerator.getInstance(KEYALG, PROVIDER);
        kpg1.initialize(new RSAKeyGenParameterSpec(size, publicExponent));
        if (!specTest(kpg1.generateKeyPair(), publicExponent)) {
            throw new RuntimeException("Test failed.");
        }
    }
项目:openjdk9    文件:SpecTest.java   
public static void main(String[] args) throws Exception {

        int size = 0;

        if (args.length >= 1) {
            size = Integer.parseInt(args[0]);
        } else {
            throw new RuntimeException("Missing keysize to test with");
        }

        BigInteger publicExponent
                = (args.length >= 2) ? new BigInteger(args[1]) : RSAKeyGenParameterSpec.F4;

        System.out.println("Running test with key size: " + size
                + " and public exponent: " + publicExponent);

        KeyPairGenerator kpg1 = KeyPairGenerator.getInstance(KEYALG, PROVIDER);
        kpg1.initialize(new RSAKeyGenParameterSpec(size, publicExponent));
        if (!specTest(kpg1.generateKeyPair(), publicExponent)) {
            throw new RuntimeException("Test failed.");
        }
    }
项目:DiyCode    文件:KeyStoreHelper.java   
@TargetApi(Build.VERSION_CODES.M)
private static void createKeysM(String alias, boolean requireAuth)
    throws NoSuchProviderException, NoSuchAlgorithmException,
    InvalidAlgorithmParameterException {
    KeyPairGenerator keyPairGenerator =
        KeyPairGenerator.getInstance(KeyProperties.KEY_ALGORITHM_RSA,
            SecurityConstants.KEYSTORE_PROVIDER_ANDROID_KEYSTORE);
    keyPairGenerator.initialize(new KeyGenParameterSpec.Builder(alias,
        KeyProperties.PURPOSE_ENCRYPT
            | KeyProperties.PURPOSE_DECRYPT).setAlgorithmParameterSpec(
        new RSAKeyGenParameterSpec(1024, F4))
        .setBlockModes(KeyProperties.BLOCK_MODE_CBC)
        .setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_RSA_PKCS1)
        .setDigests(KeyProperties.DIGEST_SHA256, KeyProperties.DIGEST_SHA384,
            KeyProperties.DIGEST_SHA512)
        // Only permit the private key to be used if the user authenticated
        // within the last five minutes.
        .setUserAuthenticationRequired(requireAuth)
        .build());
    KeyPair keyPair = keyPairGenerator.generateKeyPair();
    Log.d(TAG, "Public Key is: " + keyPair.getPublic().toString());
}
项目:conscrypt    文件:OpenSSLRSAKeyPairGenerator.java   
@Override
public void initialize(AlgorithmParameterSpec params, SecureRandom random)
        throws InvalidAlgorithmParameterException {
    if (!(params instanceof RSAKeyGenParameterSpec)) {
        throw new InvalidAlgorithmParameterException("Only RSAKeyGenParameterSpec supported");
    }

    RSAKeyGenParameterSpec spec = (RSAKeyGenParameterSpec) params;

    final BigInteger publicExponent = spec.getPublicExponent();
    if (publicExponent != null) {
        this.publicExponent = publicExponent.toByteArray();
    }

    this.modulusBits = spec.getKeysize();
}
项目:Aki-SSL    文件:KeyPairGeneratorSpi.java   
public void initialize(
    AlgorithmParameterSpec params,
    SecureRandom random)
    throws InvalidAlgorithmParameterException
{
    if (!(params instanceof RSAKeyGenParameterSpec))
    {
        throw new InvalidAlgorithmParameterException("parameter object not a RSAKeyGenParameterSpec");
    }
    RSAKeyGenParameterSpec rsaParams = (RSAKeyGenParameterSpec)params;

    param = new RSAKeyGenerationParameters(
        rsaParams.getPublicExponent(),
        random, rsaParams.getKeysize(), defaultTests);

    engine.init(param);
}
项目:javify    文件:RSAKeyPairGeneratorSpi.java   
public void initialize(AlgorithmParameterSpec params, SecureRandom random)
    throws InvalidAlgorithmParameterException
{
  HashMap attributes = new HashMap();
  if (params != null)
    {
      if (! (params instanceof RSAKeyGenParameterSpec))
        throw new InvalidAlgorithmParameterException("params");

      attributes.put(RSAKeyPairGenerator.RSA_PARAMETERS, params);
    }
  if (random != null)
    attributes.put(RSAKeyPairGenerator.SOURCE_OF_RANDOMNESS, random);

  attributes.put(RSAKeyPairGenerator.PREFERRED_ENCODING_FORMAT,
                 Integer.valueOf(Registry.ASN1_ENCODING_ID));
  adaptee.setup(attributes);
}
项目:jvm-stm    文件:RSAKeyPairGeneratorSpi.java   
public void initialize(AlgorithmParameterSpec params, SecureRandom random)
    throws InvalidAlgorithmParameterException
{
  HashMap attributes = new HashMap();
  if (params != null)
    {
      if (! (params instanceof RSAKeyGenParameterSpec))
        throw new InvalidAlgorithmParameterException("params");

      attributes.put(RSAKeyPairGenerator.RSA_PARAMETERS, params);
    }
  if (random != null)
    attributes.put(RSAKeyPairGenerator.SOURCE_OF_RANDOMNESS, random);

  attributes.put(RSAKeyPairGenerator.PREFERRED_ENCODING_FORMAT,
                 Integer.valueOf(Registry.ASN1_ENCODING_ID));
  adaptee.setup(attributes);
}
项目:L2J_LoginServer    文件:GameServerTable.java   
/**
 * Inits the RSA keys.
 */
private void initRSAKeys()
{
    try
    {
        final KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");
        keyGen.initialize(new RSAKeyGenParameterSpec(512, RSAKeyGenParameterSpec.F4));
        _keyPairs = new KeyPair[KEYS_SIZE];
        for (int i = 0; i < KEYS_SIZE; i++)
        {
            _keyPairs[i] = keyGen.genKeyPair();
        }
    }
    catch (Exception e)
    {
        LOGGER.severe(GameServerTable.class.getSimpleName() + ": Error loading RSA keys for Game Server communication!");
    }
}
项目:mycarenet    文件:CertRASession.java   
public CertRASession(String emailPrivate, String phonePrivate) throws Exception {
    KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA");
    RSAKeyGenParameterSpec params = new RSAKeyGenParameterSpec(2048, RSAKeyGenParameterSpec.F4);

    SecureRandom secureRandom = new SecureRandom();
    secureRandom.setSeed(System.currentTimeMillis());

    keyPairGenerator.initialize(params, secureRandom);
    KeyPair keyPair = keyPairGenerator.genKeyPair();

    this.privateKey = keyPair.getPrivate();
    this.publicKey = keyPair.getPublic();

    this.emailPrivate = emailPrivate;
    this.phonePrivate = phonePrivate;
}
项目:RipplePower    文件:KeyPairGeneratorSpi.java   
public void initialize(
    AlgorithmParameterSpec params,
    SecureRandom random)
    throws InvalidAlgorithmParameterException
{
    if (!(params instanceof RSAKeyGenParameterSpec))
    {
        throw new InvalidAlgorithmParameterException("parameter object not a RSAKeyGenParameterSpec");
    }
    RSAKeyGenParameterSpec rsaParams = (RSAKeyGenParameterSpec)params;

    param = new RSAKeyGenerationParameters(
        rsaParams.getPublicExponent(),
        random, rsaParams.getKeysize(), defaultTests);

    engine.init(param);
}
项目:JamVM-PH    文件:RSAKeyPairGeneratorSpi.java   
public void initialize(AlgorithmParameterSpec params, SecureRandom random)
    throws InvalidAlgorithmParameterException
{
  HashMap attributes = new HashMap();
  if (params != null)
    {
      if (! (params instanceof RSAKeyGenParameterSpec))
        throw new InvalidAlgorithmParameterException("params");

      attributes.put(RSAKeyPairGenerator.RSA_PARAMETERS, params);
    }
  if (random != null)
    attributes.put(RSAKeyPairGenerator.SOURCE_OF_RANDOMNESS, random);

  attributes.put(RSAKeyPairGenerator.PREFERRED_ENCODING_FORMAT,
                 Integer.valueOf(Registry.ASN1_ENCODING_ID));
  adaptee.setup(attributes);
}
项目:CryptMeme    文件:KeyPairGeneratorSpi.java   
public void initialize(
    AlgorithmParameterSpec params,
    SecureRandom random)
    throws InvalidAlgorithmParameterException
{
    if (!(params instanceof RSAKeyGenParameterSpec))
    {
        throw new InvalidAlgorithmParameterException("parameter object not a RSAKeyGenParameterSpec");
    }
    RSAKeyGenParameterSpec rsaParams = (RSAKeyGenParameterSpec)params;

    param = new RSAKeyGenerationParameters(
        rsaParams.getPublicExponent(),
        random, rsaParams.getKeysize(), defaultTests);

    engine.init(param);
}
项目:ripple-lib-java    文件:KeyPairGeneratorSpi.java   
public void initialize(
    AlgorithmParameterSpec params,
    SecureRandom random)
    throws InvalidAlgorithmParameterException
{
    if (!(params instanceof RSAKeyGenParameterSpec))
    {
        throw new InvalidAlgorithmParameterException("parameter object not a RSAKeyGenParameterSpec");
    }
    RSAKeyGenParameterSpec rsaParams = (RSAKeyGenParameterSpec)params;

    param = new RSAKeyGenerationParameters(
        rsaParams.getPublicExponent(),
        random, rsaParams.getKeysize(), defaultTests);

    engine.init(param);
}
项目:classpath    文件:RSAKeyPairGeneratorSpi.java   
public void initialize(AlgorithmParameterSpec params, SecureRandom random)
    throws InvalidAlgorithmParameterException
{
  HashMap attributes = new HashMap();
  if (params != null)
    {
      if (! (params instanceof RSAKeyGenParameterSpec))
        throw new InvalidAlgorithmParameterException("params");

      attributes.put(RSAKeyPairGenerator.RSA_PARAMETERS, params);
    }
  if (random != null)
    attributes.put(RSAKeyPairGenerator.SOURCE_OF_RANDOMNESS, random);

  attributes.put(RSAKeyPairGenerator.PREFERRED_ENCODING_FORMAT,
                 Integer.valueOf(Registry.ASN1_ENCODING_ID));
  adaptee.setup(attributes);
}
项目:fast-serialization    文件:I52.java   
@Test
public void test() throws Exception {
    // install BouncyCastle provider
    Security.addProvider(new BouncyCastleProvider());

    // generate a keypair
    KeyPairGenerator gen = KeyPairGenerator.getInstance("RSA", "BC");
    RSAKeyGenParameterSpec params = new RSAKeyGenParameterSpec(STRENGTH, PUBLIC_EXP);
    gen.initialize(params, new SecureRandom());
    KeyPair keyPair = gen.generateKeyPair();

    FSTConfiguration fst = FSTConfiguration.createDefaultConfiguration();

    // serialize
    byte[] serialized = fst.asByteArray(keyPair);

    // deserialize --> crash
    KeyPair deserialized = (KeyPair) fst.asObject(serialized);
}
项目:irma_future_id    文件:KeyPairGeneratorSpi.java   
public void initialize(
    AlgorithmParameterSpec params,
    SecureRandom random)
    throws InvalidAlgorithmParameterException
{
    if (!(params instanceof RSAKeyGenParameterSpec))
    {
        throw new InvalidAlgorithmParameterException("parameter object not a RSAKeyGenParameterSpec");
    }
    RSAKeyGenParameterSpec rsaParams = (RSAKeyGenParameterSpec)params;

    param = new RSAKeyGenerationParameters(
        rsaParams.getPublicExponent(),
        random, rsaParams.getKeysize(), defaultTests);

    engine.init(param);
}
项目:bc-java    文件:KeyPairGeneratorSpi.java   
public void initialize(
    AlgorithmParameterSpec params,
    SecureRandom random)
    throws InvalidAlgorithmParameterException
{
    if (!(params instanceof RSAKeyGenParameterSpec))
    {
        throw new InvalidAlgorithmParameterException("parameter object not a RSAKeyGenParameterSpec");
    }
    RSAKeyGenParameterSpec rsaParams = (RSAKeyGenParameterSpec)params;

    param = new RSAKeyGenerationParameters(
        rsaParams.getPublicExponent(),
        random, rsaParams.getKeysize(), defaultTests);

    engine.init(param);
}
项目:DroidText    文件:JDKKeyPairGenerator.java   
public void initialize(
    AlgorithmParameterSpec  params,
    SecureRandom            random)
    throws InvalidAlgorithmParameterException
{
    if (!(params instanceof RSAKeyGenParameterSpec))
    {
        throw new InvalidAlgorithmParameterException("parameter object not a RSAKeyGenParameterSpec");
    }
    RSAKeyGenParameterSpec     rsaParams = (RSAKeyGenParameterSpec)params;

    param = new RSAKeyGenerationParameters(
                    rsaParams.getPublicExponent(),
                    random, rsaParams.getKeysize(), defaultTests);

    engine.init(param);
}
项目:MoparScape    文件:KeyGenerator.java   
private void genKeys(int keyLength, String folderName) {
    if (keyLength > 0)
        this.keyLength = keyLength;
    if (folderName != null)
        this.folderName = folderName;
    if (!this.folderName.endsWith("/"))
        this.folderName += "/";
    System.out.printf("Generating %d-bit RSA keys in folder '%s'\n", this.keyLength, this.folderName);
    try {
        KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");

        // Generate a key that is keyLength bits long
        RSAKeyGenParameterSpec spec = new RSAKeyGenParameterSpec(this.keyLength, RSAKeyGenParameterSpec.F4);
        keyGen.initialize(spec);
        KeyPair pair = keyGen.generateKeyPair();
        printKeyPair(pair);
    } catch (Exception e) {
        e.printStackTrace();
    }

}
项目:L2jBrasil    文件:GameServerTable.java   
private void loadRSAKeys() throws NoSuchAlgorithmException, InvalidAlgorithmParameterException
{
    KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");
    RSAKeyGenParameterSpec spec = new RSAKeyGenParameterSpec(512,RSAKeyGenParameterSpec.F4);
    keyGen.initialize(spec);

    _keyPairs = new KeyPair[KEYS_SIZE];
    for (int i = 0; i < KEYS_SIZE; i++)
    {
        _keyPairs[i] = keyGen.genKeyPair();
    }
}
项目:quilt    文件:CryptoConditionReaderWriterTest.java   
/**
 * Setup the test.
 */
@BeforeClass
public static void setup() throws Exception {
  Provider bc = new BouncyCastleProvider();
  Security.addProvider(bc);

  final byte[] preimage = "Hello World!".getBytes(Charset.defaultCharset());
  final byte[] prefix = "Ying ".getBytes(Charset.defaultCharset());
  final byte[] message = "Yang".getBytes(Charset.defaultCharset());
  //final byte[] prefixedMessage = "Ying Yang".getBytes(Charset.defaultCharset());

  final MessageDigest sha256Digest = MessageDigest.getInstance("SHA-256");
  final MessageDigest sha512Digest = MessageDigest.getInstance("SHA-512");

  //final byte[] fingerprint = sha256Digest.digest(preimage);

  final KeyPairGenerator rsaKpg = KeyPairGenerator.getInstance("RSA");
  rsaKpg.initialize(new RSAKeyGenParameterSpec(2048, new BigInteger("65537")));
  KeyPair rsaKeyPair = rsaKpg.generateKeyPair();
  Signature rsaSigner = Signature.getInstance("SHA256withRSA/PSS");
  rsaSigner.initSign(rsaKeyPair.getPrivate());
  rsaSigner.update(message);

  net.i2p.crypto.eddsa.KeyPairGenerator edDsaKpg = new net.i2p.crypto.eddsa.KeyPairGenerator();
  KeyPair edDsaKeyPair = edDsaKpg.generateKeyPair();
  Signature edDsaSigner = new EdDSAEngine(sha512Digest);
  edDsaSigner.initSign(edDsaKeyPair.getPrivate());
  edDsaSigner.update(prefix);
  edDsaSigner.update(message);

  preimageCondition = new PreimageSha256Condition(preimage);
  rsaCondition = new RsaSha256Condition((RSAPublicKey) rsaKeyPair.getPublic());
  ed25519Condition = new Ed25519Sha256Condition((EdDSAPublicKey) edDsaKeyPair.getPublic());
  prefixSha256Condition
      = new PrefixSha256Condition(prefix, 1000, ed25519Condition);
  thresholdCondition = new ThresholdSha256Condition(
      2,
      Lists.newArrayList(preimageCondition, rsaCondition, prefixSha256Condition)
  );

  byte[] rsaSignature = rsaSigner.sign();
  byte[] edDsaSignature = edDsaSigner.sign();
  preimageFulfillment = new PreimageSha256Fulfillment(preimage);
  rsaFulfillment = new RsaSha256Fulfillment((RSAPublicKey) rsaKeyPair.getPublic(), rsaSignature);
  ed25519Fulfillment =
      new Ed25519Sha256Fulfillment((EdDSAPublicKey) edDsaKeyPair.getPublic(), edDsaSignature);
  prefixSha256Fulfillment =
      new PrefixSha256Fulfillment(prefix, 1000, ed25519Fulfillment);
  thresholdFulfillment =
      new ThresholdSha256Fulfillment(
          Lists.newArrayList(rsaCondition),
          Lists.newArrayList(preimageFulfillment, prefixSha256Fulfillment)
      );
}
项目:L2J-Global    文件:LoginController.java   
private LoginController() throws GeneralSecurityException
{
    _log.info("Loading LoginController...");

    _keyPairs = new ScrambledKeyPair[10];

    final KeyPairGenerator keygen = KeyPairGenerator.getInstance("RSA");

    final RSAKeyGenParameterSpec spec = new RSAKeyGenParameterSpec(1024, RSAKeyGenParameterSpec.F4);
    keygen.initialize(spec);

    // generate the initial set of keys
    for (int i = 0; i < 10; i++)
    {
        _keyPairs[i] = new ScrambledKeyPair(keygen.generateKeyPair());
    }
    _log.info("Cached 10 KeyPairs for RSA communication");

    testCipher((RSAPrivateKey) _keyPairs[0]._pair.getPrivate());

    // Store keys for blowfish communication
    generateBlowFishKeys();

    final Thread purge = new PurgeThread();
    purge.setDaemon(true);
    purge.start();
}
项目:OpenJSharp    文件:RSAKeyPairGenerator.java   
public void initialize(int keySize, SecureRandom random) {

        // do not allow unreasonably small or large key sizes,
        // probably user error
        try {
            RSAKeyFactory.checkKeyLengths(keySize, RSAKeyGenParameterSpec.F4,
                512, 64 * 1024);
        } catch (InvalidKeyException e) {
            throw new InvalidParameterException(e.getMessage());
        }

        this.keySize = keySize;
        this.random = random;
        this.publicExponent = RSAKeyGenParameterSpec.F4;
    }
项目:OpenJSharp    文件:RSAKeyPairGenerator.java   
public void initialize(AlgorithmParameterSpec params, SecureRandom random)
        throws InvalidAlgorithmParameterException {

    if (params instanceof RSAKeyGenParameterSpec == false) {
        throw new InvalidAlgorithmParameterException
            ("Params must be instance of RSAKeyGenParameterSpec");
    }

    RSAKeyGenParameterSpec rsaSpec = (RSAKeyGenParameterSpec)params;
    int tmpKeySize = rsaSpec.getKeysize();
    BigInteger tmpPublicExponent = rsaSpec.getPublicExponent();

    if (tmpPublicExponent == null) {
        tmpPublicExponent = RSAKeyGenParameterSpec.F4;
    } else {
        if (tmpPublicExponent.compareTo(RSAKeyGenParameterSpec.F0) < 0) {
            throw new InvalidAlgorithmParameterException
                    ("Public exponent must be 3 or larger");
        }
        if (tmpPublicExponent.bitLength() > tmpKeySize) {
            throw new InvalidAlgorithmParameterException
                    ("Public exponent must be smaller than key size");
        }
    }

    // do not allow unreasonably large key sizes, probably user error
    try {
        RSAKeyFactory.checkKeyLengths(tmpKeySize, tmpPublicExponent,
            512, 64 * 1024);
    } catch (InvalidKeyException e) {
        throw new InvalidAlgorithmParameterException(
            "Invalid key sizes", e);
    }

    this.keySize = tmpKeySize;
    this.publicExponent = tmpPublicExponent;
    this.random = random;
}
项目:OpenJSharp    文件:RSAKeyPairGenerator.java   
public void initialize(AlgorithmParameterSpec params, SecureRandom random)
        throws InvalidAlgorithmParameterException {

    int tmpSize;
    if (params == null) {
        tmpSize = KEY_SIZE_DEFAULT;
    } else if (params instanceof RSAKeyGenParameterSpec) {

        if (((RSAKeyGenParameterSpec) params).getPublicExponent() != null) {
            throw new InvalidAlgorithmParameterException
                ("Exponent parameter is not supported");
        }
        tmpSize = ((RSAKeyGenParameterSpec) params).getKeysize();

    } else {
        throw new InvalidAlgorithmParameterException
            ("Params must be an instance of RSAKeyGenParameterSpec");
    }

    try {
        RSAKeyFactory.checkKeyLengths(tmpSize, null,
            KEY_SIZE_MIN, KEY_SIZE_MAX);
    } catch (InvalidKeyException e) {
        throw new InvalidAlgorithmParameterException(
            "Invalid Key sizes", e);
    }

    this.keySize = tmpSize;
}
项目:jdk8u-jdk    文件:RSAKeyPairGenerator.java   
public void initialize(int keySize, SecureRandom random) {

        // do not allow unreasonably small or large key sizes,
        // probably user error
        try {
            RSAKeyFactory.checkKeyLengths(keySize, RSAKeyGenParameterSpec.F4,
                512, 64 * 1024);
        } catch (InvalidKeyException e) {
            throw new InvalidParameterException(e.getMessage());
        }

        this.keySize = keySize;
        this.random = random;
        this.publicExponent = RSAKeyGenParameterSpec.F4;
    }
项目:jdk8u-jdk    文件:RSAKeyPairGenerator.java   
public void initialize(AlgorithmParameterSpec params, SecureRandom random)
        throws InvalidAlgorithmParameterException {

    if (params instanceof RSAKeyGenParameterSpec == false) {
        throw new InvalidAlgorithmParameterException
            ("Params must be instance of RSAKeyGenParameterSpec");
    }

    RSAKeyGenParameterSpec rsaSpec = (RSAKeyGenParameterSpec)params;
    int tmpKeySize = rsaSpec.getKeysize();
    BigInteger tmpPublicExponent = rsaSpec.getPublicExponent();

    if (tmpPublicExponent == null) {
        tmpPublicExponent = RSAKeyGenParameterSpec.F4;
    } else {
        if (tmpPublicExponent.compareTo(RSAKeyGenParameterSpec.F0) < 0) {
            throw new InvalidAlgorithmParameterException
                    ("Public exponent must be 3 or larger");
        }
        if (tmpPublicExponent.bitLength() > tmpKeySize) {
            throw new InvalidAlgorithmParameterException
                    ("Public exponent must be smaller than key size");
        }
    }

    // do not allow unreasonably large key sizes, probably user error
    try {
        RSAKeyFactory.checkKeyLengths(tmpKeySize, tmpPublicExponent,
            512, 64 * 1024);
    } catch (InvalidKeyException e) {
        throw new InvalidAlgorithmParameterException(
            "Invalid key sizes", e);
    }

    this.keySize = tmpKeySize;
    this.publicExponent = tmpPublicExponent;
    this.random = random;
}
项目:jdk8u-jdk    文件:RSAKeyPairGenerator.java   
public void initialize(AlgorithmParameterSpec params, SecureRandom random)
        throws InvalidAlgorithmParameterException {

    int tmpSize;
    if (params == null) {
        tmpSize = KEY_SIZE_DEFAULT;
    } else if (params instanceof RSAKeyGenParameterSpec) {

        if (((RSAKeyGenParameterSpec) params).getPublicExponent() != null) {
            throw new InvalidAlgorithmParameterException
                ("Exponent parameter is not supported");
        }
        tmpSize = ((RSAKeyGenParameterSpec) params).getKeysize();

    } else {
        throw new InvalidAlgorithmParameterException
            ("Params must be an instance of RSAKeyGenParameterSpec");
    }

    try {
        RSAKeyFactory.checkKeyLengths(tmpSize, null,
            KEY_SIZE_MIN, KEY_SIZE_MAX);
    } catch (InvalidKeyException e) {
        throw new InvalidAlgorithmParameterException(
            "Invalid Key sizes", e);
    }

    this.keySize = tmpSize;
}
项目:jdk8u-jdk    文件:GenerateRSAKeyPair.java   
public static void main(String[] args) throws Exception {

        RSAKeyGenParameterSpec rsaSpec =
        new RSAKeyGenParameterSpec (1024, RSAKeyGenParameterSpec.F4);
        KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA", "SunRsaSign");
        kpg.initialize(rsaSpec);

        // test generateKeyPair
        KeyPair kpair = kpg.generateKeyPair();
        if (kpair == null) {
            throw new Exception("no keypair generated");
        }
    }
项目:jdk8u-jdk    文件:SpecTest.java   
public static void main(String[] args) {
    int failCount = 0;

    // Test key size.
    int size = Integer.parseInt(args[0]);

    try {
        KeyPairGenerator kpg1 = KeyPairGenerator.getInstance(KEYALG, PROVIDER);
        kpg1.initialize(new RSAKeyGenParameterSpec(size,
                RSAKeyGenParameterSpec.F4));
        if (!specTest(kpg1.generateKeyPair(),
                RSAKeyGenParameterSpec.F4)) {
            failCount++;
        }

        KeyPairGenerator kpg2 = KeyPairGenerator.getInstance(KEYALG, PROVIDER);
        kpg2.initialize(new RSAKeyGenParameterSpec(size,
                RSAKeyGenParameterSpec.F0));
        if (!specTest(kpg2.generateKeyPair(), RSAKeyGenParameterSpec.F0)) {
            failCount++;
        }
    } catch (NoSuchAlgorithmException | NoSuchProviderException
            | InvalidAlgorithmParameterException ex) {
        ex.printStackTrace(System.err);
        failCount++;
    }

    if (failCount != 0) {
        throw new RuntimeException("There are " + failCount
                + " tests failed.");
    }
}
项目:openjdk-jdk10    文件:RSAKeyPairGenerator.java   
public void initialize(int keySize, SecureRandom random) {

        // do not allow unreasonably small or large key sizes,
        // probably user error
        try {
            RSAKeyFactory.checkKeyLengths(keySize, RSAKeyGenParameterSpec.F4,
                512, 64 * 1024);
        } catch (InvalidKeyException e) {
            throw new InvalidParameterException(e.getMessage());
        }

        this.keySize = keySize;
        this.random = random;
        this.publicExponent = RSAKeyGenParameterSpec.F4;
    }
项目:openjdk-jdk10    文件:RSAKeyPairGenerator.java   
public void initialize(AlgorithmParameterSpec params, SecureRandom random)
        throws InvalidAlgorithmParameterException {

    if (params instanceof RSAKeyGenParameterSpec == false) {
        throw new InvalidAlgorithmParameterException
            ("Params must be instance of RSAKeyGenParameterSpec");
    }

    RSAKeyGenParameterSpec rsaSpec = (RSAKeyGenParameterSpec)params;
    int tmpKeySize = rsaSpec.getKeysize();
    BigInteger tmpPublicExponent = rsaSpec.getPublicExponent();

    if (tmpPublicExponent == null) {
        tmpPublicExponent = RSAKeyGenParameterSpec.F4;
    } else {
        if (tmpPublicExponent.compareTo(RSAKeyGenParameterSpec.F0) < 0) {
            throw new InvalidAlgorithmParameterException
                    ("Public exponent must be 3 or larger");
        }
        if (tmpPublicExponent.bitLength() > tmpKeySize) {
            throw new InvalidAlgorithmParameterException
                    ("Public exponent must be smaller than key size");
        }
    }

    // do not allow unreasonably large key sizes, probably user error
    try {
        RSAKeyFactory.checkKeyLengths(tmpKeySize, tmpPublicExponent,
            512, 64 * 1024);
    } catch (InvalidKeyException e) {
        throw new InvalidAlgorithmParameterException(
            "Invalid key sizes", e);
    }

    this.keySize = tmpKeySize;
    this.publicExponent = tmpPublicExponent;
    this.random = random;
}
项目:openjdk-jdk10    文件:RSAKeyPairGenerator.java   
public void initialize(AlgorithmParameterSpec params, SecureRandom random)
        throws InvalidAlgorithmParameterException {

    int tmpSize;
    if (params == null) {
        tmpSize = KEY_SIZE_DEFAULT;
    } else if (params instanceof RSAKeyGenParameterSpec) {

        if (((RSAKeyGenParameterSpec) params).getPublicExponent() != null) {
            throw new InvalidAlgorithmParameterException
                ("Exponent parameter is not supported");
        }
        tmpSize = ((RSAKeyGenParameterSpec) params).getKeysize();

    } else {
        throw new InvalidAlgorithmParameterException
            ("Params must be an instance of RSAKeyGenParameterSpec");
    }

    try {
        RSAKeyFactory.checkKeyLengths(tmpSize, null,
            KEY_SIZE_MIN, KEY_SIZE_MAX);
    } catch (InvalidKeyException e) {
        throw new InvalidAlgorithmParameterException(
            "Invalid Key sizes", e);
    }

    this.keySize = tmpSize;
}
项目:openjdk-jdk10    文件:GenerateRSAKeyPair.java   
public static void main(String[] args) throws Exception {

        RSAKeyGenParameterSpec rsaSpec =
        new RSAKeyGenParameterSpec (1024, RSAKeyGenParameterSpec.F4);
        KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA", "SunRsaSign");
        kpg.initialize(rsaSpec);

        // test generateKeyPair
        KeyPair kpair = kpg.generateKeyPair();
        if (kpair == null) {
            throw new Exception("no keypair generated");
        }
    }
项目:Android_Code_Arbiter    文件:InsufficientKeySizeRsa.java   
public KeyPair weakKeySize3ParameterSpec() throws NoSuchAlgorithmException, InvalidAlgorithmParameterException {
    KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");
    keyGen.initialize(new RSAKeyGenParameterSpec(128,RSAKeyGenParameterSpec.F4)); //BAD

    KeyPair key = keyGen.generateKeyPair();
    return key;
}