コード例 #1
0
    @Override
    protected void runImpl() {
      final KeyPairGenerator rsa;
      try {
        rsa = KeyPairGenerator.getInstance("RSA");
        rsa.initialize(new RSAKeyGenParameterSpec(512, RSAKeyGenParameterSpec.F4));
      } catch (GeneralSecurityException e) {
        _log.fatal("Could not generate RSA key pairs!", e);
        Shutdown.exit(TerminationStatus.ENVIRONMENT_MISSING_COMPONENT_OR_SERVICE);
        return; // never happens
      }

      final int count =
          Rnd.get(
              RSA_KEY_PAIR_COUNT / 2,
              RSA_KEY_PAIR_COUNT
                  * 3
                  / 2); // so clients will never know if they have all of them or not
      final KeyPair[] result = new KeyPair[count];

      for (int i = 0; i < count; i++) result[i] = rsa.generateKeyPair();

      _keyPairs = result;
    }
コード例 #2
0
 /**
  * Returns a RSA key pair.
  *
  * @return a key pair
  */
 public KeyPair getKeyPair() {
   return Rnd.get(getKeyPairs());
 }