chetan anurag

Greenhorn
+ Follow
since Dec 08, 2005
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by chetan anurag

How could we encrypt xml file, using Java?
CHECK OUT JDOM.jar THE BEST API FOR PARSING XML.
www.jdom.org
USE DOCUMENT OBJECT OF JDOM TO STORE THE XML OBJECT AND KEEP ADDING ELEMENTS TO IT, 3000 ELEMENTS IS NOT A BIG NUMBER AND THEN WRITE IT DOWN TO A PHYSICAL FILE. UPTO 200 MB I HAVE WORKED WITH.
CHECK IF U ARE USEING THE RIGHT OBJECT EG FOR MOZILLA AND IE HAVE DIFFERENT.
CHECK THIS CODE

// code for Mozilla, etc.
if (window.XMLHttpRequest)
{
gobjXmlHttp=new XMLHttpRequest()
gobjXmlHttp.onreadystatechange=state_Change
gobjXmlHttp.open("GET",url,true)
gobjXmlHttp.send(null)
}
// code for IE
else if (window.ActiveXObject)
{
gobjXmlHttp=new ActiveXObject("Microsoft.XMLHTTP")
if (gobjXmlHttp)
{
gobjXmlHttp.onreadystatechange=state_Change
gobjXmlHttp.open("GET",url,true)
gobjXmlHttp.send()
}
}
USE JDK 1.5
15 years ago
//TRY THIS CODE
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import java.security.Key;
import java.security.NoSuchAlgorithmException;
import java.security.InvalidKeyException;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.BadPaddingException;


/**********************************************************************
* @FileName: EncryptXML.java
* @author: chetan
* @version:
* @Creation Date: Dec 8, 2005
* @Last Modified By:
*******************************************************************/

public class EncryptXML
{
public static void main(String args[])
{
String password = "HelloWorld";
try
{
KeyGenerator kg = KeyGenerator.getInstance("DES");
Key key = kg.generateKey();
Cipher cipher = Cipher.getInstance("DES");
byte[] plain_password = password.getBytes();
String str_plain_password = new String(plain_password);
System.out.println("Plain Password = " + str_plain_password);
cipher.init(Cipher.ENCRYPT_MODE,key);
byte[] encrypted_password = cipher.doFinal(plain_password);
String str_encrypted_password = new String(encrypted_password);
System.out.println("Encrypted Password = " + str_encrypted_password);
cipher.init(Cipher.DECRYPT_MODE,key);
byte[] decrypted_password = cipher.doFinal(encrypted_password);
String str_decrypted_password = new String(decrypted_password);
System.out.println("Decrypted Password = " + str_decrypted_password);
}
catch(NoSuchAlgorithmException nsae)
{
System.out.println("No Such Algorithm Exception " + nsae.getMessage());
}
catch(NoSuchPaddingException nspe)
{
System.out.println("No Such Padding Exception " + nspe.getMessage());
}
catch(InvalidKeyException ike)
{
System.out.println("Invalid Key Exception " + ike.getMessage());
}
catch(IllegalStateException ise)
{
System.out.println("Illegal State Exception " + ise.getMessage());
}
catch(IllegalBlockSizeException ibse)
{
System.out.println("Illegal Block Size Exception " + ibse.getMessage());
}
catch(BadPaddingException bpe)
{
System.out.println("Bad Padding Exception " + bpe.getMessage());
}
}

}
15 years ago