keyinfo.java
来自「JAVA 所有包」· Java 代码 · 共 1,226 行 · 第 1/3 页
JAVA
1,226 行
/* * Copyright 1999-2004 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */package com.sun.org.apache.xml.internal.security.keys;import java.security.PublicKey;import java.security.cert.X509Certificate;import java.util.ArrayList;import java.util.List;import javax.crypto.SecretKey;import com.sun.org.apache.xml.internal.security.encryption.EncryptedKey;import com.sun.org.apache.xml.internal.security.encryption.XMLCipher;import com.sun.org.apache.xml.internal.security.encryption.XMLEncryptionException;import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException;import com.sun.org.apache.xml.internal.security.keys.content.KeyName;import com.sun.org.apache.xml.internal.security.keys.content.KeyValue;import com.sun.org.apache.xml.internal.security.keys.content.MgmtData;import com.sun.org.apache.xml.internal.security.keys.content.PGPData;import com.sun.org.apache.xml.internal.security.keys.content.RetrievalMethod;import com.sun.org.apache.xml.internal.security.keys.content.SPKIData;import com.sun.org.apache.xml.internal.security.keys.content.X509Data;import com.sun.org.apache.xml.internal.security.keys.content.keyvalues.DSAKeyValue;import com.sun.org.apache.xml.internal.security.keys.content.keyvalues.RSAKeyValue;import com.sun.org.apache.xml.internal.security.keys.keyresolver.KeyResolver;import com.sun.org.apache.xml.internal.security.keys.keyresolver.KeyResolverException;import com.sun.org.apache.xml.internal.security.keys.keyresolver.KeyResolverSpi;import com.sun.org.apache.xml.internal.security.keys.storage.StorageResolver;import com.sun.org.apache.xml.internal.security.transforms.Transforms;import com.sun.org.apache.xml.internal.security.utils.EncryptionConstants;import com.sun.org.apache.xml.internal.security.utils.Constants;import com.sun.org.apache.xml.internal.security.utils.IdResolver;import com.sun.org.apache.xml.internal.security.utils.SignatureElementProxy;import com.sun.org.apache.xml.internal.security.utils.XMLUtils;import org.w3c.dom.Document;import org.w3c.dom.Element;import org.w3c.dom.Node;import org.w3c.dom.NodeList;/** * This class stand for KeyInfo Element that may contain keys, names, * certificates and other public key management information, * such as in-band key distribution or key agreement data. * <BR /> * KeyInfo Element has two basic functions: * One is KeyResolve for getting the public key in signature validation processing. * the other one is toElement for getting the element in signature generation processing. * <BR /> * The <CODE>lengthXXX()</CODE> methods provide access to the internal Key * objects: * <UL> * <LI>If the <CODE>KeyInfo</CODE> was constructed from an Element * (Signature verification), the <CODE>lengthXXX()</CODE> methods searches * for child elements of <CODE>ds:KeyInfo</CODE> for known types. </LI> * <LI>If the <CODE>KeyInfo</CODE> was constructed from scratch (during * Signature generation), the <CODE>lengthXXX()</CODE> methods return the number * of <CODE>XXXs</CODE> objects already passed to the KeyInfo</LI> * </UL> * <BR /> * The <CODE>addXXX()</CODE> methods are used for adding Objects of the * appropriate type to the <CODE>KeyInfo</CODE>. This is used during signature * generation. * <BR /> * The <CODE>itemXXX(int i)</CODE> methods return the i'th object of the * corresponding type. * <BR /> * The <CODE>containsXXX()</CODE> methods return <I>whether</I> the KeyInfo * contains the corresponding type. * * @author $Author: raul $ */public class KeyInfo extends SignatureElementProxy { /** {@link java.util.logging} logging facility */ static java.util.logging.Logger log = java.util.logging.Logger.getLogger(KeyInfo.class.getName()); /** * Constructor KeyInfo * @param doc */ public KeyInfo(Document doc) { super(doc); XMLUtils.addReturnToElement(this._constructionElement); } /** * Constructor KeyInfo * * @param element * @param BaseURI * @throws XMLSecurityException */ public KeyInfo(Element element, String BaseURI) throws XMLSecurityException { super(element, BaseURI); } /** * Sets the <code>Id</code> attribute * * @param Id ID */ public void setId(String Id) { if ((this._state == MODE_SIGN) && (Id != null)) { this._constructionElement.setAttributeNS(null, Constants._ATT_ID, Id); IdResolver.registerElementById(this._constructionElement, Id); } } /** * Returns the <code>Id</code> attribute * * @return the <code>Id</code> attribute */ public String getId() { return this._constructionElement.getAttributeNS(null, Constants._ATT_ID); } /** * Method addKeyName * * @param keynameString */ public void addKeyName(String keynameString) { this.add(new KeyName(this._doc, keynameString)); } /** * Method add * * @param keyname */ public void add(KeyName keyname) { if (this._state == MODE_SIGN) { this._constructionElement.appendChild(keyname.getElement()); XMLUtils.addReturnToElement(this._constructionElement); } } /** * Method addKeyValue * * @param pk */ public void addKeyValue(PublicKey pk) { this.add(new KeyValue(this._doc, pk)); } /** * Method addKeyValue * * @param unknownKeyValueElement */ public void addKeyValue(Element unknownKeyValueElement) { this.add(new KeyValue(this._doc, unknownKeyValueElement)); } /** * Method add * * @param dsakeyvalue */ public void add(DSAKeyValue dsakeyvalue) { this.add(new KeyValue(this._doc, dsakeyvalue)); } /** * Method add * * @param rsakeyvalue */ public void add(RSAKeyValue rsakeyvalue) { this.add(new KeyValue(this._doc, rsakeyvalue)); } /** * Method add * * @param pk */ public void add(PublicKey pk) { this.add(new KeyValue(this._doc, pk)); } /** * Method add * * @param keyvalue */ public void add(KeyValue keyvalue) { if (this._state == MODE_SIGN) { this._constructionElement.appendChild(keyvalue.getElement()); XMLUtils.addReturnToElement(this._constructionElement); } } /** * Method addMgmtData * * @param mgmtdata */ public void addMgmtData(String mgmtdata) { this.add(new MgmtData(this._doc, mgmtdata)); } /** * Method add * * @param mgmtdata */ public void add(MgmtData mgmtdata) { if (this._state == MODE_SIGN) { this._constructionElement.appendChild(mgmtdata.getElement()); XMLUtils.addReturnToElement(this._constructionElement); } } /** * Method addPGPData * * @param pgpdata */ public void add(PGPData pgpdata) { if (this._state == MODE_SIGN) { this._constructionElement.appendChild(pgpdata.getElement()); XMLUtils.addReturnToElement(this._constructionElement); } } /** * Method addRetrievalMethod * * @param URI * @param transforms * @param Type */ public void addRetrievalMethod(String URI, Transforms transforms, String Type) { this.add(new RetrievalMethod(this._doc, URI, transforms, Type)); } /** * Method add * * @param retrievalmethod */ public void add(RetrievalMethod retrievalmethod) { if (this._state == MODE_SIGN) { this._constructionElement.appendChild(retrievalmethod.getElement()); XMLUtils.addReturnToElement(this._constructionElement); } } /** * Method add * * @param spkidata */ public void add(SPKIData spkidata) { if (this._state == MODE_SIGN) { this._constructionElement.appendChild(spkidata.getElement()); XMLUtils.addReturnToElement(this._constructionElement); } } /** * Method addX509Data * * @param x509data */ public void add(X509Data x509data) { if (this._state == MODE_SIGN) { this._constructionElement.appendChild(x509data.getElement()); XMLUtils.addReturnToElement(this._constructionElement); } } /** * Method addEncryptedKey * * @param encryptedKey * @throws XMLEncryptionException */ public void add(EncryptedKey encryptedKey) throws XMLEncryptionException { if (this._state == MODE_SIGN) { XMLCipher cipher = XMLCipher.getInstance(); this._constructionElement.appendChild(cipher.martial(encryptedKey)); } } /** * Method addUnknownElement * * @param element */ public void addUnknownElement(Element element) { if (this._state == MODE_SIGN) { this._constructionElement.appendChild(element); XMLUtils.addReturnToElement(this._constructionElement); } } /** * Method lengthKeyName * * @return the number of the KeyName tags */ public int lengthKeyName() { return this.length(Constants.SignatureSpecNS, Constants._TAG_KEYNAME); } /** * Method lengthKeyValue * *@return the number of the KeyValue tags */ public int lengthKeyValue() { return this.length(Constants.SignatureSpecNS, Constants._TAG_KEYVALUE); } /** * Method lengthMgmtData * *@return the number of the MgmtData tags */ public int lengthMgmtData() { return this.length(Constants.SignatureSpecNS, Constants._TAG_MGMTDATA); } /** * Method lengthPGPData * *@return the number of the PGPDat. tags */ public int lengthPGPData() { return this.length(Constants.SignatureSpecNS, Constants._TAG_PGPDATA); } /** * Method lengthRetrievalMethod * *@return the number of the RetrievalMethod tags */ public int lengthRetrievalMethod() { return this.length(Constants.SignatureSpecNS, Constants._TAG_RETRIEVALMETHOD); } /** * Method lengthSPKIData * *@return the number of the SPKIData tags */ public int lengthSPKIData() { return this.length(Constants.SignatureSpecNS, Constants._TAG_SPKIDATA); } /** * Method lengthX509Data * *@return the number of the X509Data tags */ public int lengthX509Data() { return this.length(Constants.SignatureSpecNS, Constants._TAG_X509DATA); } /** * Method lengthUnknownElement * NOTE posibly buggy. *@return the number of the UnknownElement tags */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?