Java Doc for KeyStore.java in  » 6.0-JDK-Modules » j2me » java » security » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » 6.0 JDK Modules » j2me » java.security 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   java.security.KeyStore

KeyStore
public class KeyStore (Code)
This class represents an in-memory collection of keys and certificates. It manages two types of entries:
  • Key Entry

    This type of keystore entry holds very sensitive cryptographic key information, which is stored in a protected format to prevent unauthorized access.

    Typically, a key stored in this type of entry is a secret key, or a private key accompanied by the certificate chain for the corresponding public key.

    Private keys and certificate chains are used by a given entity for self-authentication. Applications for this authentication include software distribution organizations which sign JAR files as part of releasing and/or licensing software.

  • Trusted Certificate Entry

    This type of entry contains a single public key certificate belonging to another party. It is called a trusted certificate because the keystore owner trusts that the public key in the certificate indeed belongs to the identity identified by the subject (owner) of the certificate.

    This type of entry can be used to authenticate other parties.

Each entry in a keystore is identified by an "alias" string. In the case of private keys and their associated certificate chains, these strings distinguish among the different ways in which the entity may authenticate itself. For example, the entity may authenticate itself using different certificate authorities, or using different public key algorithms.

Whether keystores are persistent, and the mechanisms used by the keystore if it is persistent, are not specified here. This allows use of a variety of techniques for protecting sensitive (e.g., private or secret) keys. Smart cards or other integrated cryptographic engines (SafeKeyper) are one option, and simpler mechanisms such as files may also be used (in a variety of formats).

There are two ways to request a KeyStore object: by specifying either just a keystore type, or both a keystore type and a package provider.

  • If just a keystore type is specified:
     KeyStore ks = KeyStore.getInstance("JKS");
     
    the system will determine if there is an implementation of the keystore type requested available in the environment, and if there is more than one, if there is a preferred one.

  • If both a keystore type and a package provider are specified:
     KeyStore ks = KeyStore.getInstance("JKS", "SUN");
     
    the system will determine if there is an implementation of the keystore type in the package requested, and throw an exception if there is not.

Before a keystore can be accessed, it must be KeyStore.load(java.io.InputStream,char[]) loaded . In order to create an empty keystore, you pass null as the InputStream argument to the load method.
author:
   Jan Luehe
version:
   1.29, 02/02/00
See Also:   java.security.PrivateKey
See Also:   java.security.cert.Certificate
since:
   1.2




Constructor Summary
protected  KeyStore(KeyStoreSpi keyStoreSpi, Provider provider, String type)
     Creates a KeyStore object of the given type, and encapsulates the given provider implementation (SPI object) in it.

Method Summary
final public  Enumerationaliases()
     Lists all the alias names of this keystore.
final public  booleancontainsAlias(String alias)
     Checks if the given alias exists in this keystore.
final public  voiddeleteEntry(String alias)
     Deletes the entry identified by the given alias from this keystore.
final public  CertificategetCertificate(String alias)
     Returns the certificate associated with the given alias.

If the given alias name identifies a trusted certificate entry, the certificate associated with that entry is returned.

final public  StringgetCertificateAlias(Certificate cert)
     Returns the (alias) name of the first keystore entry whose certificate matches the given certificate.

This method attempts to match the given certificate with each keystore entry.

final public  Certificate[]getCertificateChain(String alias)
     Returns the certificate chain associated with the given alias.
final public  DategetCreationDate(String alias)
     Returns the creation date of the entry identified by the given alias.
final public static  StringgetDefaultType()
     Returns the default keystore type as specified in the Java security properties file, or the string "jks" (acronym for "Java keystore") if no such property exists.
public static  KeyStoregetInstance(String type)
     Generates a keystore object of the given type.

If the default provider package provides a keystore implementation of the given type, an instance of KeyStore containing that implementation is returned.

public static  KeyStoregetInstance(String type, String provider)
     Generates a keystore object for the specified keystore type from the specified provider.
Parameters:
  type - the type of keystore.See Appendix A in the Java Cryptography Architecture API Specification & Reference for information about standard keystore types.
Parameters:
  provider - the name of the provider.
public static  KeyStoregetInstance(String type, Provider provider)
     Generates a keystore object for the specified keystore type from the specified provider.
final public  KeygetKey(String alias, char[] password)
     Returns the key associated with the given alias, using the given password to recover it.
final public  ProvidergetProvider()
     Returns the provider of this keystore.
final public  StringgetType()
     Returns the type of this keystore.
final public  booleanisCertificateEntry(String alias)
     Returns true if the entry identified by the given alias is a trusted certificate entry, and false otherwise.
final public  booleanisKeyEntry(String alias)
     Returns true if the entry identified by the given alias is a key entry, and false otherwise.
final public  voidload(InputStream stream, char[] password)
     Loads this KeyStore from the given input stream.

If a password is given, it is used to check the integrity of the keystore data.

final public  voidsetCertificateEntry(String alias, Certificate cert)
     Assigns the given certificate to the given alias.
final public  voidsetKeyEntry(String alias, Key key, char[] password, Certificate[] chain)
     Assigns the given key to the given alias, protecting it with the given password.
final public  voidsetKeyEntry(String alias, byte[] key, Certificate[] chain)
     Assigns the given key (that has already been protected) to the given alias.
final public  intsize()
     Retrieves the number of entries in this keystore.
final public  voidstore(OutputStream stream, char[] password)
     Stores this keystore to the given output stream, and protects its integrity with the given password.


Constructor Detail
KeyStore
protected KeyStore(KeyStoreSpi keyStoreSpi, Provider provider, String type)(Code)
Creates a KeyStore object of the given type, and encapsulates the given provider implementation (SPI object) in it.
Parameters:
  keyStoreSpi - the provider implementation.
Parameters:
  provider - the provider.
Parameters:
  type - the keystore type.




Method Detail
aliases
final public Enumeration aliases() throws KeyStoreException(Code)
Lists all the alias names of this keystore. enumeration of the alias names
exception:
  KeyStoreException - if the keystore has not been initialized(loaded).



containsAlias
final public boolean containsAlias(String alias) throws KeyStoreException(Code)
Checks if the given alias exists in this keystore.
Parameters:
  alias - the alias name true if the alias exists, false otherwise
exception:
  KeyStoreException - if the keystore has not been initialized(loaded).



deleteEntry
final public void deleteEntry(String alias) throws KeyStoreException(Code)
Deletes the entry identified by the given alias from this keystore.
Parameters:
  alias - the alias name
exception:
  KeyStoreException - if the keystore has not been initialized,or if the entry cannot be removed.



getCertificate
final public Certificate getCertificate(String alias) throws KeyStoreException(Code)
Returns the certificate associated with the given alias.

If the given alias name identifies a trusted certificate entry, the certificate associated with that entry is returned. If the given alias name identifies a key entry, the first element of the certificate chain of that entry is returned, or null if that entry does not have a certificate chain.
Parameters:
  alias - the alias name the certificate, or null if the given alias does not exist ordoes not contain a certificate.
exception:
  KeyStoreException - if the keystore has not been initialized(loaded).




getCertificateAlias
final public String getCertificateAlias(Certificate cert) throws KeyStoreException(Code)
Returns the (alias) name of the first keystore entry whose certificate matches the given certificate.

This method attempts to match the given certificate with each keystore entry. If the entry being considered is a trusted certificate entry, the given certificate is compared to that entry's certificate. If the entry being considered is a key entry, the given certificate is compared to the first element of that entry's certificate chain (if a chain exists).
Parameters:
  cert - the certificate to match with. the (alias) name of the first entry with matching certificate,or null if no such entry exists in this keystore.
exception:
  KeyStoreException - if the keystore has not been initialized(loaded).




getCertificateChain
final public Certificate[] getCertificateChain(String alias) throws KeyStoreException(Code)
Returns the certificate chain associated with the given alias.
Parameters:
  alias - the alias name the certificate chain (ordered with the user's certificate firstand the root certificate authority last), or null if the given aliasdoes not exist or does not contain a certificate chain (i.e., the given alias identifies either a trusted certificate entry or akey entry without a certificate chain).
exception:
  KeyStoreException - if the keystore has not been initialized(loaded).



getCreationDate
final public Date getCreationDate(String alias) throws KeyStoreException(Code)
Returns the creation date of the entry identified by the given alias.
Parameters:
  alias - the alias name the creation date of this entry, or null if the given alias doesnot exist
exception:
  KeyStoreException - if the keystore has not been initialized(loaded).



getDefaultType
final public static String getDefaultType()(Code)
Returns the default keystore type as specified in the Java security properties file, or the string "jks" (acronym for "Java keystore") if no such property exists. The Java security properties file is located in the file named <JAVA_HOME>/lib/security/java.security, where <JAVA_HOME> refers to the directory where the SDK was installed.

The default keystore type can be used by applications that do not want to use a hard-coded keystore type when calling one of the getInstance methods, and want to provide a default keystore type in case a user does not specify its own.

The default keystore type can be changed by setting the value of the "keystore.type" security property (in the Java security properties file) to the desired keystore type. the default keystore type as specified in the Java security properties file, or the string "jks"if no such property exists.




getInstance
public static KeyStore getInstance(String type) throws KeyStoreException(Code)
Generates a keystore object of the given type.

If the default provider package provides a keystore implementation of the given type, an instance of KeyStore containing that implementation is returned. If the requested keystore type is not available in the default package, other packages are searched.
Parameters:
  type - the type of keystore. See Appendix A in the Java Cryptography Architecture API Specification & Reference for information about standard keystore types. a keystore object of the specified type.
exception:
  KeyStoreException - if the requested keystore type isnot available in the default provider package or any of the otherprovider packages that were searched.




getInstance
public static KeyStore getInstance(String type, String provider) throws KeyStoreException, NoSuchProviderException(Code)
Generates a keystore object for the specified keystore type from the specified provider.
Parameters:
  type - the type of keystore.See Appendix A in the Java Cryptography Architecture API Specification & Reference for information about standard keystore types.
Parameters:
  provider - the name of the provider. a keystore object of the specified type, assupplied by the specified provider.
exception:
  KeyStoreException - if the requested keystore type is notavailable from the provider.
exception:
  NoSuchProviderException - if the provider has not beenconfigured.
exception:
  IllegalArgumentException - if the provider name is nullor empty.
See Also:   Provider



getInstance
public static KeyStore getInstance(String type, Provider provider) throws KeyStoreException(Code)
Generates a keystore object for the specified keystore type from the specified provider. Note: the provider doesn't have to be registered.
Parameters:
  type - the type of keystore.See Appendix A in the Java Cryptography Architecture API Specification & Reference for information about standard keystore types.
Parameters:
  provider - the provider. a keystore object of the specified type, assupplied by the specified provider.
exception:
  KeyStoreException - if the requested keystore type is notavailable from the provider.
exception:
  IllegalArgumentException - if the provider isnull.
See Also:   Provider
since:
   1.4



getKey
final public Key getKey(String alias, char[] password) throws KeyStoreException, NoSuchAlgorithmException, UnrecoverableKeyException(Code)
Returns the key associated with the given alias, using the given password to recover it.
Parameters:
  alias - the alias name
Parameters:
  password - the password for recovering the key the requested key, or null if the given alias does not existor does not identify a key entry.
exception:
  KeyStoreException - if the keystore has not been initialized(loaded).
exception:
  NoSuchAlgorithmException - if the algorithm for recovering thekey cannot be found
exception:
  UnrecoverableKeyException - if the key cannot be recovered(e.g., the given password is wrong).



getProvider
final public Provider getProvider()(Code)
Returns the provider of this keystore. the provider of this keystore.



getType
final public String getType()(Code)
Returns the type of this keystore. the type of this keystore.



isCertificateEntry
final public boolean isCertificateEntry(String alias) throws KeyStoreException(Code)
Returns true if the entry identified by the given alias is a trusted certificate entry, and false otherwise.
Parameters:
  alias - the alias for the keystore entry to be checked true if the entry identified by the given alias is atrusted certificate entry, false otherwise.
exception:
  KeyStoreException - if the keystore has not been initialized(loaded).



isKeyEntry
final public boolean isKeyEntry(String alias) throws KeyStoreException(Code)
Returns true if the entry identified by the given alias is a key entry, and false otherwise.
Parameters:
  alias - the alias for the keystore entry to be checked true if the entry identified by the given alias is akey entry, false otherwise.
exception:
  KeyStoreException - if the keystore has not been initialized(loaded).



load
final public void load(InputStream stream, char[] password) throws IOException, NoSuchAlgorithmException, CertificateException(Code)
Loads this KeyStore from the given input stream.

If a password is given, it is used to check the integrity of the keystore data. Otherwise, the integrity of the keystore is not checked.

In order to create an empty keystore, or if the keystore cannot be initialized from a stream (e.g., because it is stored on a hardware token device), you pass null as the stream argument.

Note that if this KeyStore has already been loaded, it is reinitialized and loaded again from the given input stream.
Parameters:
  stream - the input stream from which the keystore is loaded, ornull if an empty keystore is to be created.
Parameters:
  password - the (optional) password used to check the integrity ofthe keystore.
exception:
  IOException - if there is an I/O or format problem with thekeystore data
exception:
  NoSuchAlgorithmException - if the algorithm used to checkthe integrity of the keystore cannot be found
exception:
  CertificateException - if any of the certificates in thekeystore could not be loaded




setCertificateEntry
final public void setCertificateEntry(String alias, Certificate cert) throws KeyStoreException(Code)
Assigns the given certificate to the given alias.

If the given alias already exists in this keystore and identifies a trusted certificate entry, the certificate associated with it is overridden by the given certificate.
Parameters:
  alias - the alias name
Parameters:
  cert - the certificate
exception:
  KeyStoreException - if the keystore has not been initialized,or the given alias already exists and does not identify atrusted certificate entry, or this operation fails for someother reason.




setKeyEntry
final public void setKeyEntry(String alias, Key key, char[] password, Certificate[] chain) throws KeyStoreException(Code)
Assigns the given key to the given alias, protecting it with the given password.

If the given key is of type java.security.PrivateKey, it must be accompanied by a certificate chain certifying the corresponding public key.

If the given alias already exists, the keystore information associated with it is overridden by the given key (and possibly certificate chain).
Parameters:
  alias - the alias name
Parameters:
  key - the key to be associated with the alias
Parameters:
  password - the password to protect the key
Parameters:
  chain - the certificate chain for the corresponding publickey (only required if the given key is of typejava.security.PrivateKey).
exception:
  KeyStoreException - if the keystore has not been initialized(loaded), the given key cannot be protected, or this operation failsfor some other reason




setKeyEntry
final public void setKeyEntry(String alias, byte[] key, Certificate[] chain) throws KeyStoreException(Code)
Assigns the given key (that has already been protected) to the given alias.

If the protected key is of type java.security.PrivateKey, it must be accompanied by a certificate chain certifying the corresponding public key.

If the given alias already exists, the keystore information associated with it is overridden by the given key (and possibly certificate chain).
Parameters:
  alias - the alias name
Parameters:
  key - the key (in protected format) to be associated with the alias
Parameters:
  chain - the certificate chain for the corresponding publickey (only useful if the protected key is of typejava.security.PrivateKey).
exception:
  KeyStoreException - if the keystore has not been initialized(loaded), or if this operation fails for some other reason.




size
final public int size() throws KeyStoreException(Code)
Retrieves the number of entries in this keystore. the number of entries in this keystore
exception:
  KeyStoreException - if the keystore has not been initialized(loaded).



store
final public void store(OutputStream stream, char[] password) throws KeyStoreException, IOException, NoSuchAlgorithmException, CertificateException(Code)
Stores this keystore to the given output stream, and protects its integrity with the given password.
Parameters:
  stream - the output stream to which this keystore is written.
Parameters:
  password - the password to generate the keystore integrity check
exception:
  KeyStoreException - if the keystore has not been initialized(loaded).
exception:
  IOException - if there was an I/O problem with data
exception:
  NoSuchAlgorithmException - if the appropriate data integrityalgorithm could not be found
exception:
  CertificateException - if any of the certificates included inthe keystore data could not be stored



Methods inherited from java.lang.Object
public boolean equals(Object obj)(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.