0N/A/*
2362N/A * reserved comment block
0N/A * DO NOT REMOVE OR ALTER!
0N/A */
0N/A/*
0N/A * Copyright 1999-2004 The Apache Software Foundation.
0N/A *
0N/A * Licensed under the Apache License, Version 2.0 (the "License");
0N/A * you may not use this file except in compliance with the License.
0N/A * You may obtain a copy of the License at
0N/A *
0N/A * http://www.apache.org/licenses/LICENSE-2.0
0N/A *
0N/A * Unless required by applicable law or agreed to in writing, software
0N/A * distributed under the License is distributed on an "AS IS" BASIS,
0N/A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0N/A * See the License for the specific language governing permissions and
0N/A * limitations under the License.
0N/A *
0N/A */
0N/Apackage com.sun.org.apache.xml.internal.security.keys.content.keyvalues;
0N/A
0N/Aimport java.math.BigInteger;
0N/Aimport java.security.Key;
0N/Aimport java.security.KeyFactory;
0N/Aimport java.security.NoSuchAlgorithmException;
0N/Aimport java.security.PublicKey;
0N/Aimport java.security.interfaces.DSAPublicKey;
0N/Aimport java.security.spec.DSAPublicKeySpec;
0N/Aimport java.security.spec.InvalidKeySpecException;
0N/A
0N/Aimport com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException;
0N/Aimport com.sun.org.apache.xml.internal.security.utils.Constants;
0N/Aimport com.sun.org.apache.xml.internal.security.utils.I18n;
0N/Aimport com.sun.org.apache.xml.internal.security.utils.SignatureElementProxy;
0N/Aimport com.sun.org.apache.xml.internal.security.utils.XMLUtils;
0N/Aimport org.w3c.dom.Document;
0N/Aimport org.w3c.dom.Element;
0N/A
0N/A/**
0N/A *
0N/A * @author $Author: mullan $
0N/A */
0N/Apublic class DSAKeyValue extends SignatureElementProxy
0N/A implements KeyValueContent {
0N/A
0N/A /**
0N/A * Constructor DSAKeyValue
0N/A *
0N/A * @param element
0N/A * @param BaseURI
0N/A * @throws XMLSecurityException
0N/A */
0N/A public DSAKeyValue(Element element, String BaseURI)
0N/A throws XMLSecurityException {
0N/A super(element, BaseURI);
0N/A }
0N/A
0N/A /**
0N/A * Constructor DSAKeyValue
0N/A *
0N/A * @param doc
0N/A * @param P
0N/A * @param Q
0N/A * @param G
0N/A * @param Y
0N/A */
0N/A public DSAKeyValue(Document doc, BigInteger P, BigInteger Q, BigInteger G,
0N/A BigInteger Y) {
0N/A
0N/A super(doc);
0N/A
0N/A XMLUtils.addReturnToElement(this._constructionElement);
0N/A this.addBigIntegerElement(P, Constants._TAG_P);
0N/A this.addBigIntegerElement(Q, Constants._TAG_Q);
0N/A this.addBigIntegerElement(G, Constants._TAG_G);
0N/A this.addBigIntegerElement(Y, Constants._TAG_Y);
0N/A }
0N/A
0N/A /**
0N/A * Constructor DSAKeyValue
0N/A *
0N/A * @param doc
0N/A * @param key
0N/A * @throws IllegalArgumentException
0N/A */
0N/A public DSAKeyValue(Document doc, Key key) throws IllegalArgumentException {
0N/A
0N/A super(doc);
0N/A
0N/A XMLUtils.addReturnToElement(this._constructionElement);
0N/A
0N/A if (key instanceof java.security.interfaces.DSAPublicKey) {
0N/A this.addBigIntegerElement(((DSAPublicKey) key).getParams().getP(),
0N/A Constants._TAG_P);
0N/A this.addBigIntegerElement(((DSAPublicKey) key).getParams().getQ(),
0N/A Constants._TAG_Q);
0N/A this.addBigIntegerElement(((DSAPublicKey) key).getParams().getG(),
0N/A Constants._TAG_G);
0N/A this.addBigIntegerElement(((DSAPublicKey) key).getY(),
0N/A Constants._TAG_Y);
0N/A } else {
0N/A Object exArgs[] = { Constants._TAG_DSAKEYVALUE,
0N/A key.getClass().getName() };
0N/A
0N/A throw new IllegalArgumentException(I18n
0N/A .translate("KeyValue.IllegalArgument", exArgs));
0N/A }
0N/A }
0N/A
0N/A /** @inheritDoc */
0N/A public PublicKey getPublicKey() throws XMLSecurityException {
0N/A
0N/A try {
0N/A DSAPublicKeySpec pkspec =
0N/A new DSAPublicKeySpec(this
0N/A .getBigIntegerFromChildElement(Constants._TAG_Y, Constants
0N/A .SignatureSpecNS), this
0N/A .getBigIntegerFromChildElement(Constants._TAG_P, Constants
0N/A .SignatureSpecNS), this
0N/A .getBigIntegerFromChildElement(Constants._TAG_Q, Constants
0N/A .SignatureSpecNS), this
0N/A .getBigIntegerFromChildElement(Constants
0N/A ._TAG_G, Constants.SignatureSpecNS));
0N/A KeyFactory dsaFactory = KeyFactory.getInstance("DSA");
0N/A PublicKey pk = dsaFactory.generatePublic(pkspec);
0N/A
0N/A return pk;
0N/A } catch (NoSuchAlgorithmException ex) {
0N/A throw new XMLSecurityException("empty", ex);
0N/A } catch (InvalidKeySpecException ex) {
0N/A throw new XMLSecurityException("empty", ex);
0N/A }
0N/A }
0N/A
0N/A /** @inheritDoc */
0N/A public String getBaseLocalName() {
0N/A return Constants._TAG_DSAKEYVALUE;
0N/A }
0N/A}
0N/A