Java Examples

ChilkatHOMEAndroid™ASPVisual BasicVB.NETC#iOS (IPhone)Objective-CC++CMFCDelphiFoxProJavaPerl
PHP ExtensionPHP ActiveXPythonPowerShellRubySQL ServerVBScript

Java Examples

Quick Start
Unicode
Bz2
Certificates
CSV
Email
Encryption
FTP
HTML Conversion
HTTP
IMAP
MHT
MIME
POP3
RSA
S/MIME
SFTP
Signatures
SMTP
Socket / SSL
Spider
SSH
SSH Key
SSH Tunnel
Tar
Upload
XML
XMP
Zip

More Examples...
Amazon S3
Email Object
DKIM / DomainKey
NTLM
FileAccess
RSS
Atom
String
Byte Array
Self-Extractor
Service
PPMD
Deflate
DH Key Exchange
DSA
Bzip2
LZW

 

 

 

 

 

 

 

Encrypt XML Subtree

Encrypt an entire subtree within an XML document

 Chilkat Java Library Downloads for Windows, Linux, and MAC OS X

import com.chilkatsoft.*;

public class ChilkatExample {

  static {
    try {
        System.loadLibrary("chilkat");
    } catch (UnsatisfiedLinkError e) {
      System.err.println("Native code library failed to load.\n" + e);
      System.exit(1);
    }
  }

  public static void main(String argv[])
  {

    CkXml xml = new CkXml();

    //  First, build a sample XML document:

    CkXml xml = new CkXml();

    xml.put_Tag("stocks");

    CkXml xmlM;
    xmlM = xml.NewChild("Microsoft","");
    xmlM.NewChild2("symbol","MSFT");
    xmlM.NewChild2("recentPrice","34.50");

    CkXml xmlG;
    xmlG = xml.NewChild("Google","");
    xmlG.NewChild2("symbol","GOOG");
    xmlG.NewChild2("recentPrice","679.00");

    //  Display the unencrypted XML:
    System.out.println(xml.getXml());

    //  This is the XML displayed:
    //  <stocks>
    //      <Microsoft>
    //          <symbol>MSFT</symbol>
    //          <recentPrice>34.50</recentPrice>
    //      </Microsoft>
    //      <Google>
    //          <symbol>GOOG</symbol>
    //          <recentPrice>679.00</recentPrice>
    //      </Google>
    //  </stocks>

    //  The goal is to encrypt the "Microsoft" sub-tree.
    //  The EncryptContent method encryptes the content
    //  within a single XML node (not an entire sub-tree).
    //  Therefore, to encrypt a sub-tree,  you must first
    //  compress it into a single node, and then encrypt it.
    xmlM.ZipTree();

    //  Now encrypt the content using 128-bit AES encryption:
    xmlM.EncryptContent("secretPassword");

    //  Display the XML with the encrypted sub-tree:
    System.out.println(xml.getXml());

    //  This is displayed:
    //  <stocks>
    //      <Microsoft><![CDATA
    //  [JkiMcoK3Mi198rT30KvicDEzu5WuJgMH+8KS0UZbcRE
    //  2CtdXplphV0iCdPMYnS01O6Ly6S4QCQSReMCshG/V3
    //  8btJIZv/VLG9JZRsQk0bBafMhx7B2fQfm8YENke/JIM
    //  ]]>    </Microsoft>
    //      <Google>
    //          <symbol>GOOG</symbol>
    //          <recentPrice>679.00</recentPrice>
    //      </Google>
    //  </stocks>

    //  Now decrypt and unzip:
    xmlM.DecryptContent("secretPassword");
    boolean success;
    success = xmlM.UnzipTree();
    if (success != true) {
        System.out.println("Failed to unzip tree");
    }

    //  Display the restored document:
    System.out.println(xml.getXml());


  }
}

 

© 2000-2010 Chilkat Software, Inc. All Rights Reserved.