Results 1 to 2 of 2
- 06-29-2011, 06:30 AM #1
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.....gif)
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>
- 06-29-2011, 01:56 PM #2
Similar Threads
-
Swing application compiled in jdk1.4 is not working in jdk1.6
By jackrush in forum Advanced JavaReplies: 2Last Post: 10-22-2010, 07:54 PM -
Java applets is not working on firefox
By yanran336 in forum Java AppletsReplies: 4Last Post: 02-18-2010, 01:19 PM -
EJB invokation failing in jdk1.5.0_23 but works in jdk1.6.0
By randle169 in forum Enterprise JavaBeans (EJB)Replies: 0Last Post: 01-28-2010, 09:09 AM -
How to uninstall jdk1.4 or jdk1.5
By ran_sushmi in forum Advanced JavaReplies: 0Last Post: 07-20-2009, 12:45 PM -
JNLP - Swing application compiled in jdk1.5 not working in jdk1.6
By mahendra.athneria in forum AWT / SwingReplies: 4Last Post: 01-20-2009, 08:27 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks