Results 1 to 2 of 2
  1. #1
    karamvir17's Avatar
    karamvir17 is offline Member
    Join Date
    Jun 2011
    Location
    New Delhi, India
    Posts
    1
    Rep Power
    0

    Default Signed applets not working in JDK1.6...........!

    I have created a signed applet but it is not working in JDK 1.6.....
    It gives an AccessControlException
    In JDK 1.5 however, it works just fine........Is there a solution to this problem........somebody please help.......
    BTW, it is a program which inputs a file and encrypts its contents and then decrypts them to a new file....

    The java code for my program is :-

    Java Code:
    import java.awt.event.*;
    
    import netscape.javascript.*;
    
    import java.awt.*;
    
    import java.applet.*;
    
    import javax.swing.*;
    
    import java.io.BufferedReader;
    
    import java.io.BufferedWriter;
    
    import java.io.IOException;
    
    import java.io.FileReader;
    
    import java.io.FileWriter;
    
    import javax.crypto.Cipher;
    
    import javax.crypto.KeyGenerator;
    
    import javax.crypto.NoSuchPaddingException;
    
    import javax.crypto.BadPaddingException;
    
    import javax.crypto.IllegalBlockSizeException;
    
    import java.security.Key;
    
    import java.security.Security;
    
    import java.security.NoSuchAlgorithmException;
    
    import java.security.InvalidKeyException;
    
    import java.security.AccessControlException;
    
    
    
    public class main extends Applet implements ActionListener
    
    {
    
    	Button submit;
    
    	private static final String FNAME = "fname";
    
    	public void init()
    
    	{
    
    		submit = new Button("Submit");
    
    		add(submit);
    
    		submit.addActionListener(this);
    
    	}
    
    	public void actionPerformed(ActionEvent ae)
    
    	{
    
     		// ------------initialise connection for JavaScript/HTML --------------
    
    
    
    		JSObject win = JSObject.getWindow(this); // get HTML document
    
    		JSObject doc = (JSObject)win.eval("document.forms[0]");
    
    //		JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"docValue"+doc);
    
    
    
    		//------------ Get the name of file from HTML------------------- 
    
    
    
    		String filename = this.getParameter(FNAME);
    
    		JSObject file = (JSObject)doc.getMember(filename);
    
    		String finalfile = (String)file.getMember("value");
    
    		if(finalfile.equals(""))
    
    		{
    
    			JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"No file input. ABORTING...");
    
    			System.exit(0);
    
    		}
    
    		JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"File name:"+finalfile);
    
    
    
    		//----------------get contents of file--------------------
    
    		
    
    		String fileContent = readFile(finalfile);
    
    		JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"FileContent:"+fileContent);
    
    
    
    		//-------------------------Checking file extension---------------------------------
    
    
    
    		String ext = fileExt(finalfile);
    
    		JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"File extension is : "+ext);
    
    
    
    		//----------------Send file content to get encrypted and decrypted---------------------
    
    
    
    		String decrypted_data = encrypt_decrypt(fileContent);
    
    
    
    		//-------------------Putting Decrypted data into a new file----------------------------
    
    
    
    		newFile(decrypted_data, ext);
    
    	}
    
    	
    
    	//-----------------------Method to find file extension-----------------------------
    
    	
    
    	public String fileExt(String filename)
    
    	{
    
    		int mid = filename.lastIndexOf(".");
    
    		String ext = "";
    
    		ext = filename.substring(mid+1, filename.length());
    
    		return ext;
    
    	}
    
    
    
    	//------------------------------Method to read the inptu file------------------------
    
    	
    
    	public String readFile(String fileName)
    
    	{
    
    		String fileContent = "";
    
    		try
    
    		{
    
    			BufferedReader reader = new BufferedReader(new FileReader(fileName));
    
    			String line;
    
    			fileContent = reader.readLine();
    
    		}
    
    		catch(IOException e){}
    
    		return fileContent;
    
    	}
    
    
    
    	//----------------------Method to encrypt and decrypt data-----------------------
    
    
    
    	public String encrypt_decrypt(String data)
    
    	{
    
    		String encrypted_data = "";
    
    		String decrypted_data = "";
    
    		try
    
    		{
    
    			KeyGenerator kg = KeyGenerator.getInstance("DES");
    
    			Key key = kg.generateKey();
    
    			Cipher cipher = Cipher.getInstance("DES");
    
    			byte[] byte_data;
    
    			byte_data = data.getBytes();
    
    			cipher.init(cipher.ENCRYPT_MODE, key);
    
    			byte[] result = cipher.doFinal(byte_data);
    
    			encrypted_data = result.toString();
    
    			JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"Encrypted data is : "+encrypted_data);
    
    			cipher.init(cipher.DECRYPT_MODE, key);
    
    			byte[] original = cipher.doFinal(result);
    
    			decrypted_data = new String (original);
    
    			JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"Decrypted data is : "+decrypted_data);
    
    		}
    
    		catch(NoSuchAlgorithmException e)
    
    		{
    
    			e.printStackTrace();
    
    		}
    
    		catch(NoSuchPaddingException e)
    
    		{
    
    			e.printStackTrace();
    
    		}
    
    		catch(InvalidKeyException e)
    
    		{
    
    			e.printStackTrace();
    
    		}
    
    
    
    		catch(IllegalStateException e)
    
    		{
    
    			e.printStackTrace();
    
    		}
    
    
    
    		catch(IllegalBlockSizeException e)
    
    		{
    
    			e.printStackTrace();
    
    		}
    
    
    
    		catch(BadPaddingException e)
    
    		{
    
    			e.printStackTrace();
    
    		}
    
    		return decrypted_data;
    
    	}
    
    
    
    	//----------------------Method to write decrypted data to new file---------------------
    
    
    
    	public void newFile(String data, String ext)
    
    	{
    
    		String filename = "H:\\karamvir_javap\\Encryption_Decryption_Together\\newfile."+ext;
    
    		JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"New file created is : "+filename);
    
    		try
    
    		{
    
    		BufferedWriter writer = new BufferedWriter(new FileWriter(filename));
    
    		writer.write(data);
    
    		writer.close();
    
    		}
    
    		catch (IOException e)
    
    		{
    
    		}
    
    		JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"New file created is 2 : "+filename);
    
    	}
    
    }

    The HTML code is :-


    Java Code:
    <html>
    
    <body>
    
    <form name="frm">
    
    <p>File:<input type="file" name="File"></p>
    
    <object classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" width="300" height="100">
    
    <param name="archive" value="myjarfile.jar">
    
    <param name="code" value="main">
    
    <param name="type" value="application/x-java-applet;version=1.6">
    
    <param name="mayscript" value="true">
    
    <param name="scriptable" value="false">
    
    <param name="fname" value="File">
    
    <param name="submit" value="SUBMIT">
    
    <comment>
    
    <embed code="main" width="300" height="100" mayscript="mayscript" scriptable="true" archive="myjarfile.jar" type="application/x-java-applet;version=1.6" fname="File" submit="SUBMIT"> 
    
    </embed>
    
    </comment>
    
    </object>
    
    </form>
    
    </body>
    
    </html>

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,266
    Rep Power
    25

    Default

    When posting error messages, Please post the full text of the message.

Similar Threads

  1. Replies: 2
    Last Post: 10-22-2010, 07:54 PM
  2. Java applets is not working on firefox
    By yanran336 in forum Java Applets
    Replies: 4
    Last Post: 02-18-2010, 01:19 PM
  3. EJB invokation failing in jdk1.5.0_23 but works in jdk1.6.0
    By randle169 in forum Enterprise JavaBeans (EJB)
    Replies: 0
    Last Post: 01-28-2010, 09:09 AM
  4. How to uninstall jdk1.4 or jdk1.5
    By ran_sushmi in forum Advanced Java
    Replies: 0
    Last Post: 07-20-2009, 12:45 PM
  5. JNLP - Swing application compiled in jdk1.5 not working in jdk1.6
    By mahendra.athneria in forum AWT / Swing
    Replies: 4
    Last Post: 01-20-2009, 08:27 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •