IBM®
跳转到主要内容
    中国 [选择]    使用条款
 
 
Select a scope: Search for:    
    首页    产品    服务与解决方案     支持与下载    个性化服务    
跳转到主要内容

developerWorks 中国  >  XML  >

Exploring XML Encryption, Part 1

Demonstrating the secure exchange of structured data

developerWorks

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.

    关于 IBM 隐私条约 联系 IBM 使用条款