src/share/classes/java/security/KeyStore.java

Print this page




  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package java.security;
  27 
  28 import java.io.*;
  29 import java.security.cert.Certificate;
  30 import java.security.cert.X509Certificate;
  31 import java.security.cert.CertificateException;
  32 import java.util.*;
  33 import javax.crypto.SecretKey;
  34 

  35 import javax.security.auth.callback.*;
  36 
  37 /**
  38  * This class represents a storage facility for cryptographic
  39  * keys and certificates.
  40  *
  41  * <p> A <code>KeyStore</code> manages different types of entries.
  42  * Each type of entry implements the <code>KeyStore.Entry</code> interface.
  43  * Three basic <code>KeyStore.Entry</code> implementations are provided:
  44  *
  45  * <ul>
  46  * <li><b>KeyStore.PrivateKeyEntry</b>
  47  * <p> This type of entry holds a cryptographic <code>PrivateKey</code>,
  48  * which is optionally stored in a protected format to prevent
  49  * unauthorized access.  It is also accompanied by a certificate chain
  50  * for the corresponding public key.
  51  *
  52  * <p> Private keys and certificate chains are used by a given entity for
  53  * self-authentication. Applications for this authentication include software
  54  * distribution organizations which sign JAR files as part of releasing


 261          * after it is no longer needed.
 262          *
 263          * @see #destroy()
 264          * @return the password, which may be <code>null</code>
 265          * @exception IllegalStateException if the password has
 266          *              been cleared (destroyed)
 267          */
 268         public synchronized char[] getPassword() {
 269             if (destroyed) {
 270                 throw new IllegalStateException("password has been cleared");
 271             }
 272             return password;
 273         }
 274 
 275         /**
 276          * Clears the password.
 277          *
 278          * @exception DestroyFailedException if this method was unable
 279          *      to clear the password
 280          */
 281         public synchronized void destroy()
 282                 throws javax.security.auth.DestroyFailedException {
 283             destroyed = true;
 284             if (password != null) {
 285                 Arrays.fill(password, ' ');
 286             }
 287         }
 288 
 289         /**
 290          * Determines if password has been cleared.
 291          *
 292          * @return true if the password has been cleared, false otherwise
 293          */
 294         public synchronized boolean isDestroyed() {
 295             return destroyed;
 296         }
 297     }
 298 
 299     /**
 300      * A ProtectionParameter encapsulating a CallbackHandler.
 301      *
 302      * @since 1.5




  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package java.security;
  27 
  28 import java.io.*;
  29 import java.security.cert.Certificate;
  30 import java.security.cert.X509Certificate;
  31 import java.security.cert.CertificateException;
  32 import java.util.*;
  33 import javax.crypto.SecretKey;
  34 
  35 import javax.security.auth.DestroyFailedException;
  36 import javax.security.auth.callback.*;
  37 
  38 /**
  39  * This class represents a storage facility for cryptographic
  40  * keys and certificates.
  41  *
  42  * <p> A <code>KeyStore</code> manages different types of entries.
  43  * Each type of entry implements the <code>KeyStore.Entry</code> interface.
  44  * Three basic <code>KeyStore.Entry</code> implementations are provided:
  45  *
  46  * <ul>
  47  * <li><b>KeyStore.PrivateKeyEntry</b>
  48  * <p> This type of entry holds a cryptographic <code>PrivateKey</code>,
  49  * which is optionally stored in a protected format to prevent
  50  * unauthorized access.  It is also accompanied by a certificate chain
  51  * for the corresponding public key.
  52  *
  53  * <p> Private keys and certificate chains are used by a given entity for
  54  * self-authentication. Applications for this authentication include software
  55  * distribution organizations which sign JAR files as part of releasing


 262          * after it is no longer needed.
 263          *
 264          * @see #destroy()
 265          * @return the password, which may be <code>null</code>
 266          * @exception IllegalStateException if the password has
 267          *              been cleared (destroyed)
 268          */
 269         public synchronized char[] getPassword() {
 270             if (destroyed) {
 271                 throw new IllegalStateException("password has been cleared");
 272             }
 273             return password;
 274         }
 275 
 276         /**
 277          * Clears the password.
 278          *
 279          * @exception DestroyFailedException if this method was unable
 280          *      to clear the password
 281          */
 282         public synchronized void destroy() throws DestroyFailedException {

 283             destroyed = true;
 284             if (password != null) {
 285                 Arrays.fill(password, ' ');
 286             }
 287         }
 288 
 289         /**
 290          * Determines if password has been cleared.
 291          *
 292          * @return true if the password has been cleared, false otherwise
 293          */
 294         public synchronized boolean isDestroyed() {
 295             return destroyed;
 296         }
 297     }
 298 
 299     /**
 300      * A ProtectionParameter encapsulating a CallbackHandler.
 301      *
 302      * @since 1.5