1 /* 2 * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 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 * $Id: KeyValue.java,v 1.4 2005/05/10 16:35:35 mullan Exp $ 27 */ 28 package javax.xml.crypto.dsig.keyinfo; 29 30 import java.security.KeyException; 31 import java.security.KeyStore; 32 import java.security.PublicKey; 33 import java.security.interfaces.DSAPublicKey; 34 import java.security.interfaces.RSAPublicKey; 35 import javax.xml.crypto.XMLStructure; 36 37 /** 38 * A representation of the XML <code>KeyValue</code> element as defined 39 * in the <a href="http://www.w3.org/TR/xmldsig-core/"> 40 * W3C Recommendation for XML-Signature Syntax and Processing</a>. A 41 * <code>KeyValue</code> object contains a single public key that may be 42 * useful in validating the signature. The XML schema definition is defined as: 43 * 44 * <pre> 45 * <element name="KeyValue" type="ds:KeyValueType"/> 46 * <complexType name="KeyValueType" mixed="true"> 47 * <choice> 48 * <element ref="ds:DSAKeyValue"/> 49 * <element ref="ds:RSAKeyValue"/> 50 * <any namespace="##other" processContents="lax"/> 51 * </choice> 52 * </complexType> 53 * 54 * <element name="DSAKeyValue" type="ds:DSAKeyValueType"/> 55 * <complexType name="DSAKeyValueType"> 56 * <sequence> 57 * <sequence minOccurs="0"> 58 * <element name="P" type="ds:CryptoBinary"/> 59 * <element name="Q" type="ds:CryptoBinary"/> 60 * </sequence> 61 * <element name="G" type="ds:CryptoBinary" minOccurs="0"/> 62 * <element name="Y" type="ds:CryptoBinary"/> 63 * <element name="J" type="ds:CryptoBinary" minOccurs="0"/> 64 * <sequence minOccurs="0"> 65 * <element name="Seed" type="ds:CryptoBinary"/> 66 * <element name="PgenCounter" type="ds:CryptoBinary"/> 67 * </sequence> 68 * </sequence> 69 * </complexType> 70 * 71 * <element name="RSAKeyValue" type="ds:RSAKeyValueType"/> 72 * <complexType name="RSAKeyValueType"> 73 * <sequence> 74 * <element name="Modulus" type="ds:CryptoBinary"/> 75 * <element name="Exponent" type="ds:CryptoBinary"/> 76 * </sequence> 77 * </complexType> 78 * </pre> 79 * A <code>KeyValue</code> instance may be created by invoking the 80 * {@link KeyInfoFactory#newKeyValue newKeyValue} method of the 81 * {@link KeyInfoFactory} class, and passing it a {@link 82 * java.security.PublicKey} representing the value of the public key. Here is 83 * an example of creating a <code>KeyValue</code> from a {@link DSAPublicKey} 84 * of a {@link java.security.cert.Certificate} stored in a 85 * {@link java.security.KeyStore}: 86 * <pre> 87 * KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType()); 88 * PublicKey dsaPublicKey = keyStore.getCertificate("myDSASigningCert").getPublicKey(); 89 * KeyInfoFactory factory = KeyInfoFactory.getInstance("DOM"); 90 * KeyValue keyValue = factory.newKeyValue(dsaPublicKey); 91 * </pre> 92 * 93 * This class returns the <code>DSAKeyValue</code> and 94 * <code>RSAKeyValue</code> elements as objects of type 95 * {@link DSAPublicKey} and {@link RSAPublicKey}, respectively. Note that not 96 * all of the fields in the schema are accessible as parameters of these 97 * types. 98 * 99 * @author Sean Mullan 100 * @author JSR 105 Expert Group 101 * @since 1.6 102 * @see KeyInfoFactory#newKeyValue(PublicKey) 103 */ 104 public interface KeyValue extends XMLStructure { 105 106 /** 107 * URI identifying the DSA KeyValue KeyInfo type: 108 * http://www.w3.org/2000/09/xmldsig#DSAKeyValue. This can be specified as 109 * the value of the <code>type</code> parameter of the 110 * {@link RetrievalMethod} class to describe a remote 111 * <code>DSAKeyValue</code> structure. 112 */ 113 final static String DSA_TYPE = 114 "http://www.w3.org/2000/09/xmldsig#DSAKeyValue"; 115 116 /** 117 * URI identifying the RSA KeyValue KeyInfo type: 118 * http://www.w3.org/2000/09/xmldsig#RSAKeyValue. This can be specified as 119 * the value of the <code>type</code> parameter of the 120 * {@link RetrievalMethod} class to describe a remote 121 * <code>RSAKeyValue</code> structure. 122 */ 123 final static String RSA_TYPE = 124 "http://www.w3.org/2000/09/xmldsig#RSAKeyValue"; 125 126 /** 127 * Returns the public key of this <code>KeyValue</code>. 128 * 129 * @return the public key of this <code>KeyValue</code> 130 * @throws KeyException if this <code>KeyValue</code> cannot be converted 131 * to a <code>PublicKey</code> 132 */ 133 PublicKey getPublicKey() throws KeyException; 134 }