// engine method public override void Initialize(int keysize, SecureRandom random) { if (ServiceIterator == null) { Spi.Initialize(keysize, random); return; } RuntimeException failure = null; KeyPairGeneratorSpi mySpi = Spi; do { try { mySpi.Initialize(keysize, random); InitType = I_SIZE; InitKeySize = keysize; InitParams = null; InitRandom = random; return; } catch (RuntimeException e) { if (failure == null) { failure = e; } mySpi = NextSpi(mySpi, false); } } while (mySpi != null); throw failure; }
/// <summary> /// Update the active spi of this class and return the next /// implementation for failover. If no more implemenations are /// available, this method returns null. However, the active spi of /// this class is never set to null. /// </summary> internal KeyPairGeneratorSpi NextSpi(KeyPairGeneratorSpi oldSpi, bool reinit) { lock (@lock) { // somebody else did a failover concurrently // try that spi now if ((oldSpi != null) && (oldSpi != Spi)) { return(Spi); } if (ServiceIterator == null) { return(null); } while (ServiceIterator.HasNext()) { Service s = ServiceIterator.Next(); try { Object inst = s.NewInstance(null); // ignore non-spis if (inst is KeyPairGeneratorSpi == false) { continue; } if (inst is KeyPairGenerator) { continue; } KeyPairGeneratorSpi spi = (KeyPairGeneratorSpi)inst; if (reinit) { if (InitType == I_SIZE) { spi.Initialize(InitKeySize, InitRandom); } else if (InitType == I_PARAMS) { spi.Initialize(InitParams, InitRandom); } else if (InitType != I_NONE) { throw new AssertionError("KeyPairGenerator initType: " + InitType); } } Provider_Renamed = s.Provider; this.Spi = spi; return(spi); } catch (Exception) { // ignore } } DisableFailover(); return(null); } }
// engine method //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public void initialize(java.security.spec.AlgorithmParameterSpec params, SecureRandom random) throws InvalidAlgorithmParameterException public override void Initialize(AlgorithmParameterSpec @params, SecureRandom random) { if (ServiceIterator == null) { Spi.Initialize(@params, random); return; } Exception failure = null; KeyPairGeneratorSpi mySpi = Spi; do { try { mySpi.Initialize(@params, random); InitType = I_PARAMS; InitKeySize = 0; InitParams = @params; InitRandom = random; return; } catch (Exception e) { if (failure == null) { failure = e; } mySpi = NextSpi(mySpi, false); } } while (mySpi != null); if (failure is RuntimeException) { throw (RuntimeException)failure; } // must be an InvalidAlgorithmParameterException throw (InvalidAlgorithmParameterException)failure; }