1 17 package com.sun.org.apache.xml.internal.security.keys.content.keyvalues; 18 19 20 21 import java.math.BigInteger ; 22 import java.security.Key ; 23 import java.security.KeyFactory ; 24 import java.security.NoSuchAlgorithmException ; 25 import java.security.PublicKey ; 26 import java.security.interfaces.DSAPublicKey ; 27 import java.security.spec.DSAPublicKeySpec ; 28 import java.security.spec.InvalidKeySpecException ; 29 30 import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException; 31 import com.sun.org.apache.xml.internal.security.utils.Constants; 32 import com.sun.org.apache.xml.internal.security.utils.I18n; 33 import com.sun.org.apache.xml.internal.security.utils.SignatureElementProxy; 34 import com.sun.org.apache.xml.internal.security.utils.XMLUtils; 35 import org.w3c.dom.Document ; 36 import org.w3c.dom.Element ; 37 38 39 43 public class DSAKeyValue extends SignatureElementProxy 44 implements KeyValueContent { 45 46 47 static java.util.logging.Logger log = 48 java.util.logging.Logger.getLogger(DSAKeyValue.class.getName()); 49 50 57 public DSAKeyValue(Element element, String BaseURI) 58 throws XMLSecurityException { 59 super(element, BaseURI); 60 } 61 62 71 public DSAKeyValue(Document doc, BigInteger P, BigInteger Q, BigInteger G, 72 BigInteger Y) { 73 74 super(doc); 75 76 XMLUtils.addReturnToElement(this._constructionElement); 77 this.addBigIntegerElement(P, Constants._TAG_P); 78 this.addBigIntegerElement(Q, Constants._TAG_Q); 79 this.addBigIntegerElement(G, Constants._TAG_G); 80 this.addBigIntegerElement(Y, Constants._TAG_Y); 81 } 82 83 90 public DSAKeyValue(Document doc, Key key) throws IllegalArgumentException { 91 92 super(doc); 93 94 XMLUtils.addReturnToElement(this._constructionElement); 95 96 if (key instanceof java.security.interfaces.DSAPublicKey ) { 97 this.addBigIntegerElement(((DSAPublicKey ) key).getParams().getP(), 98 Constants._TAG_P); 99 this.addBigIntegerElement(((DSAPublicKey ) key).getParams().getQ(), 100 Constants._TAG_Q); 101 this.addBigIntegerElement(((DSAPublicKey ) key).getParams().getG(), 102 Constants._TAG_G); 103 this.addBigIntegerElement(((DSAPublicKey ) key).getY(), 104 Constants._TAG_Y); 105 } else { 106 Object exArgs[] = { Constants._TAG_DSAKEYVALUE, 107 key.getClass().getName() }; 108 109 throw new IllegalArgumentException (I18n 110 .translate("KeyValue.IllegalArgument", exArgs)); 111 } 112 } 113 114 115 public PublicKey getPublicKey() throws XMLSecurityException { 116 117 try { 118 DSAPublicKeySpec pkspec = 119 new DSAPublicKeySpec (this 120 .getBigIntegerFromChildElement(Constants._TAG_Y, Constants 121 .SignatureSpecNS), this 122 .getBigIntegerFromChildElement(Constants._TAG_P, Constants 123 .SignatureSpecNS), this 124 .getBigIntegerFromChildElement(Constants._TAG_Q, Constants 125 .SignatureSpecNS), this 126 .getBigIntegerFromChildElement(Constants 127 ._TAG_G, Constants.SignatureSpecNS)); 128 KeyFactory dsaFactory = KeyFactory.getInstance("DSA"); 129 PublicKey pk = dsaFactory.generatePublic(pkspec); 130 131 return pk; 132 } catch (NoSuchAlgorithmException ex) { 133 throw new XMLSecurityException("empty", ex); 134 } catch (InvalidKeySpecException ex) { 135 throw new XMLSecurityException("empty", ex); 136 } 137 } 138 139 140 public String getBaseLocalName() { 141 return Constants._TAG_DSAKEYVALUE; 142 } 143 } 144 | Popular Tags |