code: public KeyPair getKeyPair(int bits)
          throws NoSuchAlgorithmException, NoSuchProviderException {
  
          if (this.lifetime < 1) {
  
              logger.debug("Cache lifetime is less than 1, generating new " +
                           "keypair each time");
              KeyPairGenerator generator =
                  KeyPairGenerator.getInstance(this.algorithm, this.provider);
              generator.initialize(bits);
              return generator.generateKeyPair();
          }
  
          long st = System.currentTimeMillis();
          Integer keysize = new Integer(bits);
          KeyPairCacheEntry entry = (KeyPairCacheEntry)entries.get(keysize);
          if (entry == null || st - entry.getCreatedAt() >= lifetime) {
              logger.debug("Creating " + bits + " bits keypair");
  
              KeyPairGenerator generator =
                  KeyPairGenerator.getInstance(algorithm, provider);
              generator.initialize(bits);
              logger.debug("Time to generate key pair: " +
                           (System.currentTimeMillis() - st));
  
              entry = new KeyPairCacheEntry(generator.generateKeyPair(), st);
              entries.put(keysize, entry);
          }
          return entry.getKeyPair();
      }
docs: Returns a key pair of size <code>bits</code>. The same key pair
  may be returned several times within a period of the cache
  lifetime.
  
  If lifetime was set to zero or less than zero, no keys are cached.
  
  @param bits the keysize. This is an algorithm-specific metric,
  such as modulus length, specified in number of bits.
  @throws NoSuchAlgorithmException if the algorithm is not
  available in the environment.
  @throws NoSuchProviderException if the provider is not
  available in the environment.