Наследование: java.lang.Object
Пример #1
0
            // 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;
            }
Пример #2
0
            // engine method
            public override KeyPair GenerateKeyPair()
            {
                if (ServiceIterator == null)
                {
                    return(Spi.GenerateKeyPair());
                }
                RuntimeException    failure = null;
                KeyPairGeneratorSpi mySpi   = Spi;

                do
                {
                    try
                    {
                        return(mySpi.GenerateKeyPair());
                    }
                    catch (RuntimeException e)
                    {
                        if (failure == null)
                        {
                            failure = e;
                        }
                        mySpi = NextSpi(mySpi, true);
                    }
                } while (mySpi != null);
                throw failure;
            }
Пример #3
0
 /// <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);
     }
 }
Пример #4
0
            internal Delegate(Instance instance, Iterator <Service> serviceIterator, String algorithm) : base(algorithm)
            {
                Spi = (KeyPairGeneratorSpi)instance.impl;
                Provider_Renamed     = instance.provider;
                this.ServiceIterator = serviceIterator;
                InitType             = I_NONE;

                if (!SkipDebug && Pdebug != null)
                {
                    Pdebug.println("KeyPairGenerator." + algorithm + " algorithm from: " + Provider_Renamed.Name);
                }
            }
Пример #5
0
        private static KeyPairGenerator GetInstance(Instance instance, String algorithm)
        {
            KeyPairGenerator kpg;

            if (instance.impl is KeyPairGenerator)
            {
                kpg = (KeyPairGenerator)instance.impl;
            }
            else
            {
                KeyPairGeneratorSpi spi = (KeyPairGeneratorSpi)instance.impl;
                kpg = new Delegate(spi, algorithm);
            }
            kpg.Provider_Renamed = instance.provider;

            if (!SkipDebug && Pdebug != null)
            {
                Pdebug.println("KeyPairGenerator." + algorithm + " algorithm from: " + kpg.Provider_Renamed.Name);
            }

            return(kpg);
        }
Пример #6
0
            // 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;
            }
Пример #7
0
 // constructor
 internal Delegate(KeyPairGeneratorSpi spi, String algorithm) : base(algorithm)
 {
     this.Spi = spi;
 }