Skip to main content

By clicking Submit, you agree to the developerWorks terms of use.

The first time you sign into developerWorks, a profile is created for you. Select information in your profile (name, country/region, and company) is displayed to the public and will accompany any content you post. You may update your IBM account at any time.

All information submitted is secure.

  • Close [x]

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerworks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

By clicking Submit, you agree to the developerWorks terms of use.

All information submitted is secure.

  • Close [x]

Exploring XML Encryption, Part 1

Demonstrating the secure exchange of structured data

Return to article.


Listing 14. Authors the KeyInfo element


 /*
 	DW/BS
	20020204
	GenericKeyInfo.java
	Listing 14
	Authors the KeyInfo element.
 */

import org.w3c.dom.*;

public class GenericKeyInfo {

	// Element to hold complete XML Structure.
	protected Element keyInfo = null;
	protected Document doc = null;

	// Element will be appended in Document only once.
	protected boolean elementAppendedToDoc = false;

	
	// Default constructor.
	public GenericKeyInfo (Document document, String nsQlif, int typeNo) {
		doc = document;
		
		keyInfo = doc.createElement(nsQlif + ":KeyInfo");
		
		// Add the namespace attribute.
		keyInfo.setAttribute("xmlns:" + nsQlif, AlgoNames.getAlgoNSValue(typeNo));
	}// End GenericKeyInfo
	
	// Add KeyName child in KeyInfo
	public void setKeyName(String keyName) {
		Element tempElem = doc.createElement("KeyName");
		tempElem.appendChild(doc.createTextNode(keyName));
		keyInfo.appendChild(tempElem);
	}// End setKeyName()
	
	// Add KeyValue child in KeyInfo
	public void setKeyValue (String keyValue){
		Element tempElem = doc.createElement("KeyValue");
		tempElem.appendChild(doc.createTextNode(keyValue));
		keyInfo.appendChild(tempElem);
	}// End setKeyValue()
	
	// Set retrieval Method URI and and Its type.
	public void setRetrievalMethod (String uriValue, int typeNo) {
		Element tempElem = doc.createElement("RetrievalMethod");
		tempElem.setAttribute("URI", uriValue);
		tempElem.setAttribute("Type", AlgoNames.getAlgoNSValue(typeNo));
		keyInfo.appendChild(tempElem);
	}// End setRetrievalMethod() 
	
	// Return the complete XML structure as a Document Object.
	public Document getKeyInfo() {
		if (elementAppendedToDoc == false ) {
			doc.appendChild(keyInfo);
			elementAppendedToDoc = true;
		}
	 	return doc;
	}// End getKeyInfo()
} // end class KeyInfo

Return to article.