1 17 package com.sun.org.apache.xml.internal.security.keys.content; 18 19 20 21 import java.security.PublicKey ; 22 23 24 import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException; 25 import com.sun.org.apache.xml.internal.security.keys.content.keyvalues.DSAKeyValue; 26 import com.sun.org.apache.xml.internal.security.keys.content.keyvalues.RSAKeyValue; 27 import com.sun.org.apache.xml.internal.security.utils.Constants; 28 import com.sun.org.apache.xml.internal.security.utils.SignatureElementProxy; 29 import com.sun.org.apache.xml.internal.security.utils.XMLUtils; 30 import org.w3c.dom.Document ; 31 import org.w3c.dom.Element ; 32 33 34 43 public class KeyValue extends SignatureElementProxy implements KeyInfoContent { 44 45 46 static java.util.logging.Logger log = 47 java.util.logging.Logger.getLogger(KeyValue.class.getName()); 48 49 55 public KeyValue(Document doc, DSAKeyValue dsaKeyValue) { 56 57 super(doc); 58 59 XMLUtils.addReturnToElement(this._constructionElement); 60 this._constructionElement.appendChild(dsaKeyValue.getElement()); 61 XMLUtils.addReturnToElement(this._constructionElement); 62 } 63 64 70 public KeyValue(Document doc, RSAKeyValue rsaKeyValue) { 71 72 super(doc); 73 74 XMLUtils.addReturnToElement(this._constructionElement); 75 this._constructionElement.appendChild(rsaKeyValue.getElement()); 76 XMLUtils.addReturnToElement(this._constructionElement); 77 } 78 79 85 public KeyValue(Document doc, Element unknownKeyValue) { 86 87 super(doc); 88 89 XMLUtils.addReturnToElement(this._constructionElement); 90 this._constructionElement.appendChild(unknownKeyValue); 91 XMLUtils.addReturnToElement(this._constructionElement); 92 } 93 94 100 public KeyValue(Document doc, PublicKey pk) { 101 102 super(doc); 103 104 XMLUtils.addReturnToElement(this._constructionElement); 105 106 if (pk instanceof java.security.interfaces.DSAPublicKey ) { 107 DSAKeyValue dsa = new DSAKeyValue(this._doc, pk); 108 109 this._constructionElement.appendChild(dsa.getElement()); 110 XMLUtils.addReturnToElement(this._constructionElement); 111 } else if (pk instanceof java.security.interfaces.RSAPublicKey ) { 112 RSAKeyValue rsa = new RSAKeyValue(this._doc, pk); 113 114 this._constructionElement.appendChild(rsa.getElement()); 115 XMLUtils.addReturnToElement(this._constructionElement); 116 } 117 } 118 119 126 public KeyValue(Element element, String BaseURI) 127 throws XMLSecurityException { 128 super(element, BaseURI); 129 } 130 131 137 public PublicKey getPublicKey() throws XMLSecurityException { 138 139 140 Element rsa = XMLUtils.selectDsNode(this._constructionElement.getFirstChild(), 141 Constants._TAG_RSAKEYVALUE,0); 142 143 if (rsa != null) { 144 RSAKeyValue kv = new RSAKeyValue(rsa, 145 this._baseURI); 146 147 return kv.getPublicKey(); 148 } 149 150 Element dsa = XMLUtils.selectDsNode(this._constructionElement, 151 Constants._TAG_DSAKEYVALUE,0); 152 153 154 if (dsa != null) { 155 DSAKeyValue kv = new DSAKeyValue(dsa, 156 this._baseURI); 157 158 return kv.getPublicKey(); 159 } 160 161 162 return null; 163 } 164 165 166 public String getBaseLocalName() { 167 return Constants._TAG_KEYVALUE; 168 } 169 } 170 | Popular Tags |