/// <summary> /// Translates a key object, whose provider may be unknown or potentially /// untrusted, into a corresponding key object of this key factory. /// </summary> /// <param name="key"> the key whose provider is unknown or untrusted. /// </param> /// <returns> the translated key. /// </returns> /// <exception cref="InvalidKeyException"> if the given key cannot be processed /// by this key factory. </exception> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public final Key translateKey(Key key) throws InvalidKeyException public Key TranslateKey(Key key) { if (ServiceIterator == null) { return(Spi.EngineTranslateKey(key)); } Exception failure = null; KeyFactorySpi mySpi = Spi; do { try { return(mySpi.EngineTranslateKey(key)); } catch (Exception e) { if (failure == null) { failure = e; } mySpi = NextSpi(mySpi); } } while (mySpi != null); if (failure is RuntimeException) { throw (RuntimeException)failure; } if (failure is InvalidKeyException) { throw (InvalidKeyException)failure; } throw new InvalidKeyException("Could not translate key", failure); }
/// <summary> /// Returns a specification (key material) of the given key object. /// {@code keySpec} identifies the specification class in which /// the key material should be returned. It could, for example, be /// {@code DSAPublicKeySpec.class}, to indicate that the /// key material should be returned in an instance of the /// {@code DSAPublicKeySpec} class. /// </summary> /// @param <T> the type of the key specification to be returned /// </param> /// <param name="key"> the key. /// </param> /// <param name="keySpec"> the specification class in which /// the key material should be returned. /// </param> /// <returns> the underlying key specification (key material) in an instance /// of the requested specification class. /// </returns> /// <exception cref="InvalidKeySpecException"> if the requested key specification is /// inappropriate for the given key, or the given key cannot be processed /// (e.g., the given key has an unrecognized algorithm or format). </exception> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public final <T extends java.security.spec.KeySpec> T getKeySpec(Key key, Class keySpec) throws java.security.spec.InvalidKeySpecException public T getKeySpec <T>(Key key, Class keySpec) where T : java.security.spec.KeySpec { if (ServiceIterator == null) { return(Spi.EngineGetKeySpec(key, keySpec)); } Exception failure = null; KeyFactorySpi mySpi = Spi; do { try { return(mySpi.EngineGetKeySpec(key, keySpec)); } catch (Exception e) { if (failure == null) { failure = e; } mySpi = NextSpi(mySpi); } } while (mySpi != null); if (failure is RuntimeException) { throw (RuntimeException)failure; } if (failure is InvalidKeySpecException) { throw (InvalidKeySpecException)failure; } throw new InvalidKeySpecException("Could not get key spec", failure); }
/// <summary> /// Generates a private key object from the provided key specification /// (key material). /// </summary> /// <param name="keySpec"> the specification (key material) of the private key. /// </param> /// <returns> the private key. /// </returns> /// <exception cref="InvalidKeySpecException"> if the given key specification /// is inappropriate for this key factory to produce a private key. </exception> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public final PrivateKey generatePrivate(java.security.spec.KeySpec keySpec) throws java.security.spec.InvalidKeySpecException public PrivateKey GeneratePrivate(KeySpec keySpec) { if (ServiceIterator == null) { return(Spi.EngineGeneratePrivate(keySpec)); } Exception failure = null; KeyFactorySpi mySpi = Spi; do { try { return(mySpi.EngineGeneratePrivate(keySpec)); } catch (Exception e) { if (failure == null) { failure = e; } mySpi = NextSpi(mySpi); } } while (mySpi != null); if (failure is RuntimeException) { throw (RuntimeException)failure; } if (failure is InvalidKeySpecException) { throw (InvalidKeySpecException)failure; } throw new InvalidKeySpecException("Could not generate private key", failure); }
/// <summary> /// Update the active KeyFactorySpi 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> private KeyFactorySpi NextSpi(KeyFactorySpi oldSpi) { 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 obj = s.NewInstance(null); if (obj is KeyFactorySpi == false) { continue; } KeyFactorySpi spi = (KeyFactorySpi)obj; Provider_Renamed = s.Provider; this.Spi = spi; return(spi); } catch (NoSuchAlgorithmException) { // ignore } } ServiceIterator = null; return(null); } }
/// <summary> /// Creates a KeyFactory object. /// </summary> /// <param name="keyFacSpi"> the delegate </param> /// <param name="provider"> the provider </param> /// <param name="algorithm"> the name of the algorithm /// to associate with this {@code KeyFactory} </param> protected internal KeyFactory(KeyFactorySpi keyFacSpi, Provider provider, String algorithm) { this.Spi = keyFacSpi; this.Provider_Renamed = provider; this.Algorithm_Renamed = algorithm; }