KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > xml > crypto > dsig > keyinfo > KeyValue


1 /*
2  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
3  */

4 /*
5  * $Id: KeyValue.java,v 1.4 2005/05/10 16:35:35 mullan Exp $
6  */

7 package javax.xml.crypto.dsig.keyinfo;
8
9 import java.security.KeyException JavaDoc;
10 import java.security.KeyStore JavaDoc;
11 import java.security.PublicKey JavaDoc;
12 import java.security.interfaces.DSAPublicKey JavaDoc;
13 import java.security.interfaces.RSAPublicKey JavaDoc;
14 import javax.xml.crypto.XMLStructure;
15
16 /**
17  * A representation of the XML <code>KeyValue</code> element as defined
18  * in the <a HREF="http://www.w3.org/TR/xmldsig-core/">
19  * W3C Recommendation for XML-Signature Syntax and Processing</a>. A
20  * <code>KeyValue</code> object contains a single public key that may be
21  * useful in validating the signature. The XML schema definition is defined as:
22  *
23  * <pre>
24  * &lt;element name="KeyValue" type="ds:KeyValueType"/&gt;
25  * &lt;complexType name="KeyValueType" mixed="true"&gt;
26  * &lt;choice&gt;
27  * &lt;element ref="ds:DSAKeyValue"/&gt;
28  * &lt;element ref="ds:RSAKeyValue"/&gt;
29  * &lt;any namespace="##other" processContents="lax"/&gt;
30  * &lt;/choice&gt;
31  * &lt;/complexType&gt;
32  *
33  * &lt;element name="DSAKeyValue" type="ds:DSAKeyValueType"/&gt;
34  * &lt;complexType name="DSAKeyValueType"&gt;
35  * &lt;sequence&gt;
36  * &lt;sequence minOccurs="0"&gt;
37  * &lt;element name="P" type="ds:CryptoBinary"/&gt;
38  * &lt;element name="Q" type="ds:CryptoBinary"/&gt;
39  * &lt;/sequence&gt;
40  * &lt;element name="G" type="ds:CryptoBinary" minOccurs="0"/&gt;
41  * &lt;element name="Y" type="ds:CryptoBinary"/&gt;
42  * &lt;element name="J" type="ds:CryptoBinary" minOccurs="0"/&gt;
43  * &lt;sequence minOccurs="0"&gt;
44  * &lt;element name="Seed" type="ds:CryptoBinary"/&gt;
45  * &lt;element name="PgenCounter" type="ds:CryptoBinary"/&gt;
46  * &lt;/sequence&gt;
47  * &lt;/sequence&gt;
48  * &lt;/complexType&gt;
49  *
50  * &lt;element name="RSAKeyValue" type="ds:RSAKeyValueType"/&gt;
51  * &lt;complexType name="RSAKeyValueType"&gt;
52  * &lt;sequence&gt;
53  * &lt;element name="Modulus" type="ds:CryptoBinary"/&gt;
54  * &lt;element name="Exponent" type="ds:CryptoBinary"/&gt;
55  * &lt;/sequence&gt;
56  * &lt;/complexType&gt;
57  * </pre>
58  * A <code>KeyValue</code> instance may be created by invoking the
59  * {@link KeyInfoFactory#newKeyValue newKeyValue} method of the
60  * {@link KeyInfoFactory} class, and passing it a {@link
61  * java.security.PublicKey} representing the value of the public key. Here is
62  * an example of creating a <code>KeyValue</code> from a {@link DSAPublicKey}
63  * of a {@link java.security.cert.Certificate} stored in a
64  * {@link java.security.KeyStore}:
65  * <pre>
66  * KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
67  * PublicKey dsaPublicKey = keyStore.getCertificate("myDSASigningCert").getPublicKey();
68  * KeyInfoFactory factory = KeyInfoFactory.getInstance("DOM");
69  * KeyValue keyValue = factory.newKeyValue(dsaPublicKey);
70  * </pre>
71  *
72  * This class returns the <code>DSAKeyValue</code> and
73  * <code>RSAKeyValue</code> elements as objects of type
74  * {@link DSAPublicKey} and {@link RSAPublicKey}, respectively. Note that not
75  * all of the fields in the schema are accessible as parameters of these
76  * types.
77  *
78  * @author Sean Mullan
79  * @author JSR 105 Expert Group
80  * @since 1.6
81  * @see KeyInfoFactory#newKeyValue(PublicKey)
82  */

83 public interface KeyValue extends XMLStructure {
84
85     /**
86      * URI identifying the DSA KeyValue KeyInfo type:
87      * http://www.w3.org/2000/09/xmldsig#DSAKeyValue. This can be specified as
88      * the value of the <code>type</code> parameter of the
89      * {@link RetrievalMethod} class to describe a remote
90      * <code>DSAKeyValue</code> structure.
91      */

92     final static String JavaDoc DSA_TYPE =
93         "http://www.w3.org/2000/09/xmldsig#DSAKeyValue";
94
95     /**
96      * URI identifying the RSA KeyValue KeyInfo type:
97      * http://www.w3.org/2000/09/xmldsig#RSAKeyValue. This can be specified as
98      * the value of the <code>type</code> parameter of the
99      * {@link RetrievalMethod} class to describe a remote
100      * <code>RSAKeyValue</code> structure.
101      */

102     final static String JavaDoc RSA_TYPE =
103         "http://www.w3.org/2000/09/xmldsig#RSAKeyValue";
104
105     /**
106      * Returns the public key of this <code>KeyValue</code>.
107      *
108      * @return the public key of this <code>KeyValue</code>
109      * @throws KeyException if this <code>KeyValue</code> cannot be converted
110      * to a <code>PublicKey</code>
111      */

112     PublicKey JavaDoc getPublicKey() throws KeyException JavaDoc;
113 }
114
Popular Tags