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 15. Authors the CipherData element

 
/*
 	DW/BS
	20020204
	CipherData.java
	Listing 15
	Authors the CipherData element.
 */

import org.w3c.dom.*;

public class CipherData {
	
	// We will create child elements within this document.
	private Document doc = null;
	
	// The main structure.
	private Element cipherData = null;

	// Element will be appended in Document only once.
	private boolean elementAppendedToDoc = false;
	
	// Constructor
	public CipherData(Document document){
		doc = document;
		cipherData = doc.createElement("CipherData");

		elementAppendedToDoc = false;
	}// End CipherData()

	// Sets the encrypted Data inside CipherValue Child tag.
	public void setValue(String value){
		Element tempElem = doc.createElement("CipherValue");
		tempElem.appendChild(doc.createTextNode(value));
		cipherData.appendChild(tempElem);
	}// End setValue()

	// Adds CipherReference element inside CipherData element.
	// Its Attribute URI is passed as parameter.
	// Transform element is optional.
	// If want to set only URI then pass NULL in place of transforms Element
	public void setCipherReference (String uriValue, Element transforms) {
		Element tempElem = doc.createElement("CipherReference");
		tempElem.setAttribute("URI", uriValue);
		
		if ( transforms != null )
			tempElem.appendChild(transforms);
		
		cipherData.appendChild(tempElem);
	}// End setCipherReference()
	
	// Retuns the completed CipherData structure.
	public Document getCipherData() {
		if (elementAppendedToDoc == false ) {
			doc.appendChild(cipherData);
			elementAppendedToDoc = true;
		}
		return doc;
	}// End getCipherData()
}// end Class CipherData

Return to article.