Beispiel #1
0
  public AsymmetricCipherKeyPair getKeyPair(
      int keySize, String algorithm, String RNGAlgorithm, String RNGProvider) {
    AsymmetricCipherKeyPair pair = serverKeys.get(algorithm);
    if (pair != null) {
      return pair;
    }

    if (provider == null) {
      return pair;
    }

    SecureRandom secureRandom = getSecureRandom(RNGAlgorithm, RNGProvider);
    if (secureRandom == null) {
      return null;
    }

    AsymmetricCipherKeyPairGenerator generator = getGenerator(algorithm);

    if (generator == null) {
      return null;
    }

    initGenerator(keySize, algorithm, generator, secureRandom);

    AsymmetricCipherKeyPair newPair = generator.generateKeyPair();

    AsymmetricCipherKeyPair oldPair = serverKeys.putIfAbsent(algorithm, newPair);
    if (oldPair != null) {
      return oldPair;
    }

    return newPair;
  }
Beispiel #2
0
 public void initGenerator(
     int keySize,
     String algorithm,
     AsymmetricCipherKeyPairGenerator generator,
     SecureRandom random) {
   if (algorithm.equals("RSA")) {
     RSAKeyGenerationParameters params =
         new RSAKeyGenerationParameters(new BigInteger("10001", 16), random, keySize, 80);
     generator.init(params);
   }
 }