?? keystore.java
字號:
/* KeyStore.java --- Key Store Class Copyright (C) 1999, 2002, 2003, 2004 Free Software Foundation, Inc.This file is part of GNU Classpath.GNU Classpath is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2, or (at your option)any later version.GNU Classpath is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public Licensealong with GNU Classpath; see the file COPYING. If not, write to theFree Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA02110-1301 USA.Linking this library statically or dynamically with other modules ismaking a combined work based on this library. Thus, the terms andconditions of the GNU General Public License cover the wholecombination.As a special exception, the copyright holders of this library give youpermission to link this library with independent modules to produce anexecutable, regardless of the license terms of these independentmodules, and to copy and distribute the resulting executable underterms of your choice, provided that you also meet, for each linkedindependent module, the terms and conditions of the license of thatmodule. An independent module is a module which is not derived fromor based on this library. If you modify this library, you may extendthis exception to your version of the library, but you are notobligated to do so. If you do not wish to do so, delete thisexception statement from your version. */package java.security;import gnu.java.security.Engine;import java.io.IOException;import java.io.InputStream;import java.io.OutputStream;import java.security.cert.CertificateException;import java.util.Date;import java.util.Enumeration;/** * Keystore represents an in-memory collection of keys and * certificates. There are two types of entries: * * <dl> * <dt>Key Entry</dt> * * <dd><p>This type of keystore entry store sensitive crytographic key * information in a protected format.Typically this is a secret * key or a private key with a certificate chain.</p></dd> * * <dt>Trusted Ceritificate Entry</dt> * * <dd><p>This type of keystore entry contains a single public key * certificate belonging to annother entity. It is called trusted * because the keystore owner trusts that the certificates * belongs to the subject (owner) of the certificate.</p></dd> * </dl> * * <p>Entries in a key store are referred to by their "alias": a simple * unique string. * * <p>The structure and persistentence of the key store is not * specified. Any method could be used to protect sensitive * (private or secret) keys. Smart cards or integrated * cryptographic engines could be used or the keystore could * be simply stored in a file.</p> * * @see java.security.cert.Certificate * @see Key */public class KeyStore{ // Constants and fields. // ------------------------------------------------------------------------ /** Service name for key stores. */ private static final String KEY_STORE = "KeyStore"; private KeyStoreSpi keyStoreSpi; private Provider provider; private String type; // Constructors. // ------------------------------------------------------------------------ /** Creates an instance of KeyStore @param keyStoreSpi A KeyStore engine to use @param provider A provider to use @param type The type of KeyStore */ protected KeyStore(KeyStoreSpi keyStoreSpi, Provider provider, String type) { this.keyStoreSpi = keyStoreSpi; this.provider = provider; this.type = type; } // Class methods. // ------------------------------------------------------------------------ /** * Gets an instance of the KeyStore class representing * the specified keystore. If the type is not * found then, it throws KeyStoreException. * * @param type the type of keystore to choose * @return a KeyStore repesenting the desired type * @throws KeyStoreException if the type of keystore is not implemented * by providers or the implementation cannot be instantiated. */ public static KeyStore getInstance(String type) throws KeyStoreException { Provider[] p = Security.getProviders(); for (int i = 0; i < p.length; i++) { try { return getInstance(type, p[i]); } catch (KeyStoreException e) { // Ignore. } } throw new KeyStoreException(type); } /** * Gets an instance of the KeyStore class representing * the specified key store from the specified provider. * If the type is not found then, it throws KeyStoreException. * If the provider is not found, then it throws * NoSuchProviderException. * * @param type the type of keystore to choose * @param provider the provider name * @return a KeyStore repesenting the desired type * @throws KeyStoreException if the type of keystore is not * implemented by the given provider * @throws NoSuchProviderException if the provider is not found * @throws IllegalArgumentException if the provider string is * null or empty */ public static KeyStore getInstance(String type, String provider) throws KeyStoreException, NoSuchProviderException { if (provider == null || provider.length() == 0) throw new IllegalArgumentException("Illegal provider"); Provider p = Security.getProvider(provider); if (p == null) throw new NoSuchProviderException(provider); return getInstance(type, p); } /** * Gets an instance of the KeyStore class representing * the specified key store from the specified provider. * If the type is not found then, it throws KeyStoreException. * If the provider is not found, then it throws * NoSuchProviderException. * * @param type the type of keystore to choose * @param provider the keystore provider * @return a KeyStore repesenting the desired type * @throws KeyStoreException if the type of keystore is not * implemented by the given provider * @throws IllegalArgumentException if the provider object is null * @since 1.4 */ public static KeyStore getInstance(String type, Provider provider) throws KeyStoreException { if (provider == null) throw new IllegalArgumentException("Illegal provider"); try { return new KeyStore( (KeyStoreSpi) Engine.getInstance(KEY_STORE, type, provider), provider, type); } catch (NoSuchAlgorithmException nsae) { throw new KeyStoreException(type); } catch (java.lang.reflect.InvocationTargetException ite) { throw new KeyStoreException(type); } catch (ClassCastException cce) { throw new KeyStoreException(type); } } /** * Returns the default KeyStore type. This method looks up the * type in <JAVA_HOME>/lib/security/java.security with the * property "keystore.type" or if that fails then "jks" . */ public static final String getDefaultType() { // Security reads every property in java.security so it // will return this property if it exists. String tmp = Security.getProperty("keystore.type"); if (tmp == null) tmp = "jks"; return tmp; } // Instance methods. // ------------------------------------------------------------------------ /** Gets the provider that the class is from. @return the provider of this class */ public final Provider getProvider() { return provider; } /** Returns the type of the KeyStore supported @return A string with the type of KeyStore */ public final String getType() { return type; } /** Returns the key associated with given alias using the supplied password.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -