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; 10 import java.security.KeyStore; 11 import java.security.PublicKey; 12 import java.security.interfaces.DSAPublicKey; 13 import java.security.interfaces.RSAPublicKey; 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 * <element name="KeyValue" type="ds:KeyValueType"/> 25 * <complexType name="KeyValueType" mixed="true"> 26 * <choice> 27 * <element ref="ds:DSAKeyValue"/> 28 * <element ref="ds:RSAKeyValue"/> 29 * <any namespace="##other" processContents="lax"/> 30 * </choice> 31 * </complexType> 32 * 33 * <element name="DSAKeyValue" type="ds:DSAKeyValueType"/> 34 * <complexType name="DSAKeyValueType"> 35 * <sequence> 36 * <sequence minOccurs="0"> 37 * <element name="P" type="ds:CryptoBinary"/> 38 * <element name="Q" type="ds:CryptoBinary"/> 39 * </sequence> 40 * <element name="G" type="ds:CryptoBinary" minOccurs="0"/> 41 * <element name="Y" type="ds:CryptoBinary"/> 42 * <element name="J" type="ds:CryptoBinary" minOccurs="0"/> 43 * <sequence minOccurs="0"> 44 * <element name="Seed" type="ds:CryptoBinary"/> 45 * <element name="PgenCounter" type="ds:CryptoBinary"/> 46 * </sequence> 47 * </sequence> 48 * </complexType> 49 * 50 * <element name="RSAKeyValue" type="ds:RSAKeyValueType"/> 51 * <complexType name="RSAKeyValueType"> 52 * <sequence> 53 * <element name="Modulus" type="ds:CryptoBinary"/> 54 * <element name="Exponent" type="ds:CryptoBinary"/> 55 * </sequence> 56 * </complexType> 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 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 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 getPublicKey() throws KeyException; 113 } 114