Can I Use Jce in applet

Hi all,
Thanks for everybody first if you look at my question and try to help me to find out the problem.
I need to write a applet which can let people to use
the jce's des function to encipher the user's password and
id from the homepage.
I write a applet already. It work fine as a application.
But it doesn't work when I run it as a applet. Does the problem come from the security problem because I need
to Load a sun_jce provider in a clien machine ?
Can I use JCE in applet ?
If it is ok to use jce in developing applet do I need to sign the applet before run it in web and which file I need to sign.
Btw, I use the archive tag in html file to make user get the whole jce jar file. does it Ok.
Followin is my source code
import javax.crypto.*;
import javax.crypto.spec.*;
import java.security.*;
import sun.misc.*;
import java.applet.*;
import java.awt.*;
public class DesApplet extends Applet{
     public static void main(String[] arg) throws Exception{
          DesApplet des = new DesApplet();
          des.CallDes();
     public void init(){
          CallDes();
     public void paint(Graphics g){
     public CallDes(){
          Cipher desCipher;
          int i;                              
          try{
               Security.addProvider(new com.sun.crypto.provider.SunJCE());
               KeyGenerator keygen = KeyGenerator.getInstance("DES");
               SecretKey desKey = new SecretKeySpec("11111111".getBytes(),"DES");
               System.out.println("Hello");
               desCipher = Cipher.getInstance("DES/ECB/NoPadding");
               desCipher.init(Cipher.ENCRYPT_MODE,desKey);
               byte[] cleartext = "00000000".getBytes();
               String value = convert_int_to_hex(cleartext,8);
               System.out.println("cleartext is:"+value);
               byte[] ciphertext = desCipher.doFinal(cleartext);
               value = convert_int_to_hex(ciphertext,8);
               System.out.println("ciphertext is:"+value);
               desCipher.init(Cipher.DECRYPT_MODE,desKey);
               byte[] cleartext1 = desCipher.doFinal(ciphertext);;
               value = convert_int_to_hex(cleartext1,8);
               System.out.println("cleartext1 is:"+value);
          }catch(Exception e){System.err.println(e);}
     public String convert_int_to_hex(byte[] value, int len) {
     int i;
     int j;
     byte tmp;
     byte[] temp = new byte[len*2];
     char[] chars = new char[len*2];
     String result = new String();
     for (i=0; i<len; i++)
     if (value[i] < 0)
     temp[i*2] = (byte)((value[i] & 0xF0) >>> 4);
     temp[i*2+1] = (byte)(value[i] & 0x0F);
     else
     temp[i*2] = (byte)(value[i] / 16);
     temp[i*2+1] = (byte)(value[i] % 16);
     for (i=0; i<len*2; i++)
     if (temp[i] > 9)
     chars[i] = (char)(temp[i] - 10 + 65);
     else
     chars[i] = (char)(temp[i] + 48);
     result = result.concat(result.valueOf(chars));
     return result;

I have a server and a client.
Server has jdk1.4. client is an applet. I need to encrypt the username and password that are sent from client to the server.
I am able to encrypt and decrypt using JCE's DES on server side, since jdk1.4 has JCE provider installed by default. Since the applet may be running on any browser which may not have JCE supported. Is it possible for me to send the JCE jar file along with the applet and somehow enable the client applet to encrypt the user name and password and send to server.
Thanks a lot,
Gagan.

Similar Messages

  • Can I use AWT and Applets in a J2EE project???

    Hi,
    I adore applets and the package AWT... And I would like to know if some way exists to integrate my applet with my application J2EE... I want to use these in the vision tier in a J2EE(EJB) project...
    How can I make that my applet acts as an observing process of my model??? If the JVM will be informed on any alterations in the model will be the JVM of the server while my applet will be being executed for the JVM of browser...
    []'s
    Ary Junior

    I have a J2EE application, for which I have a module which is used by system administrators. this module is completly written in Java swing.
    and it does talk to my EJBs.
    If you don't have a firewall in your application, then you can directly make your applications in awt, swing and applets talk to EJBs. if you do have a firewall, then just write a web-service wrapper over your EJBs and other J2EE components and use them from desktop applications.
    It seems that you want to implement a kind of a applet based monitor application for your J2EE EJBs on the server. Applets cannot directly monitor your EJBs.
    Create a new module which has a service which acts as an event listener on the server. each j2ee component on the server notify it if there is a change to them. this service, can then write the data realted to the modification on a socket which is continiously being read by the applet. So you can implement a kind of a monitor for J2ee apps with applets.
    hope this helps.
    regards,
    Abhishek.
    PS:How did you manage to adore the AWT ;-) ? I found that it sucks (good performance.. very poor lnf) ... java swing sucks too (very poor performance ... avaerage lnf).

  • Can we use JCE embedded into JAVA 1.5 outside USA and Canada?

    Hello all,
    in the old JCE 1.2.2 (http://java.sun.com/products/archive/jce/) where was a restriction: RESTRICTED TO THE UNITED STATES AND CANADA. If you do not reside in the United States or Canada, you will not be able to download this software.
    Is there the same restriction also in the embedded JCE into java 1.5 ?
    I can not see any restriction. is it correct?
    Could you give me the link where I can find the restriction or the license and term of use about JCE embedded in JAVA 1.5?
    Thanks
    Matteo

    Those restrictions were lifted during the Clinton administration.

  • Please help!!how can i use clipboard in applet?

    please

    Hi,
    use this example for copy
    import java.awt.datatransfer.*;
    Clipboard sysClipboard;
    sysClipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    public void copy()
    {     String text = formText.getSelectedText();
         if(text == null)
         text = "";
         if(text.equals("")) text = formText.getText();
         StringSelection selection = new StringSelection(text);
         sysClipboard.setContents(selection, null);
    make a jar, sign the jar, generate keys
    put this in your policy file
    grant signedBy "yourname"
    {     permission java.awt.AWTPermission "accessClipboard";
    http://galileo.spaceports.com/~ibidris/

  • Can't use "java" command

    I just can't use the java command...
    The paths have been set and everything should work...
    If I just type "java" (without the "") I get:
    Usage: java [-options] class [args...]
    (to execute a class)
    or java -jar [-options] jarfile [args...]
    (to execute a jar file)
    where options include:
    -client to select the "client" VM
    -server to select the "server" VM
    -hotspot is a synonym for the "client" VM [deprecated]
    The default VM is client.
    -cp -classpath <directories and zip/jar files separated by ;>
    set search path for application classes and resources
    -D<name>=<value>
    set a system property
    -verbose[:class|gc|jni]
    enable verbose output
    -version print product version and exit
    -showversion print product version and continue
    -? -help print this help message
    -X print help on non-standard options
    -ea[:<packagename>...|:<classname>]
    -enableassertions[:<packagename>...|:<classname>]
    enable assertions
    -da[:<packagename>...|:<classname>]
    -disableassertions[:<packagename>...|:<classname>]
    disable assertions
    -esa | -enablesystemassertions
    enable system assertions
    -dsa | -disablesystemassertions
    disable system assertions
    And if I type "java Oper" (It compiled normally and worked on my school computer) it gives me this error:
    Exception in thread "main" java.lang.NoClassDefFoundError: Oper
    It works everywhere but on my computer...
    Oh, and I have Java Builder 3 University Edition installed. When I use that to compile + run my program, it works perfectely... I just can't use "java" in command prompt. I have a Windows ME.
    Another note, this may be related: I can't use certain Java applets on my computer, like the IRC applets for example. I tried it on both Netscape 7.01 and Internet Explorer 6.0.2800.1106. It displays the same kind of error, the Exception in thread "..." java.lang.NoClassDefFoundError: ... .
    And I've already tried uninstalling + reinstalling. Any other suggestions?

    start -> run -> cmd
    (if it doesn't open command prompt, then try command instead of cmd)
    once you have reached command prompt, then you change to some empty directory where you would like to create java or class files. (use cd command for that)
    once you have reached that directory, type: notepad Hello.java
    (it should open notepad, and it should prompt you a question if you want to create file Hello.java (since it didn't excist) ... click yes)
    in notepad type the following:class Hello {
    public static void main(String[] args) {
      System.out.println("Hello");
    }once you have written that into notepad, then click File and choose Save from there.
    now you may close your notepad.
    now go back to that command prompt and type in command dir Hello.*
    it should lis you all Hello.* files, and Hello.java should be one of these.
    now, when you have seen that in your current directory a Hello.java does excist, you may type javac Hello.java
    if it does compile whitout any errors then everything is OK so far.
    type again dir Hello.*
    now you should see two files, Hello.java and Hello.class
    if you now saw that Hello.class was in the current directory, you may type the following command: java Hello
    it should display a String "Hello" on your screen.
    if it doesn't work, then you have problem with java not working from commandline (some classpaths are wrong or unset or smthng similar)
    if you suspect that something doesn't work, then always test it with simplest task.

  • Can I use radio with bluetooth?

    Im wondering if you have a BLUETOOTH headset, and nothing is plugged into the earphone jack, can you use the radio applet?

    No.

  • How can I use applet to get the desktop image of client

    hi,I have a question to ask u.
    How can I use applet to get the desktop image of client? Now I develop a web application and want user in the client to get his current image of the screen.And then save as a picture of jpeg format ,then upload it to the server?
    I have done an application to get the screen image and do upload file to server in a servlet with the http protocal.

    Since the desktop image is on the client's local hard drive, you'll need to look at trusted applets first.

  • Can parport be used in a applet?

    I have been trying to get parport to read and write in an applet but have had no success. It works fine at the command line but when used in the applet it stops my applet program when it comes to executing the read function.
    My first idea was keep the parport read and write codes completely seperate from the applet in their own class file and then call the class file to be run. Is this at all possible?
    I have posted the code to see if i can make this clearer
    import parport.ParallelPort;
    class SimpleIO {
    public static void main ( String []args )
    ParallelPort lpt1 = new ParallelPort(0x378); // 0x378 is normally the base address for the LPT1 port
    int aByte;
    aByte = lpt1.read(); // read a byte from the port's STATUS pins
    System.out.println("Input from parallel port: " + aByte);
    aByte = aByte >> 2; // a simple and irrelevant operation
    lpt1.write(aByte); // write a byte to the port's DATA pins
    System.out.println("Output to port: " + aByte);
    //////////////This code above will be kept in its own java file called SIMPLEIO.java////////
    I then want to call and run this code from my applet java file. After some experimenting i think i have found out that you need the
    public static void main ( String []args ) line in the parport code in order for it work properly. What code would i use to call and run this code from the applet file
    Thx for reading my long post and thx to all who try and help me out

    My first idea was keep the parport read and write codes completely seperate from the applet in their
    own class file and then call the class file to be run. Is this at all possible?No. The problem is that applets run in what's called a sandbox which prevents them, and any classes called from them, from doing any local IO.
    This is essential for security, since a web page can run an applet without the user knowing about it, and it could get up to all kinds of mischief.
    You can digitally sign the applet, which will then ask the user for permission to run with reduced restrictions. A quick search of java/sun should turn up some instructions.

  • How can I use URLConnection to use applet communication with servlet?

    I want to send a String to a servlet in applet.I now use URLConnection to communicat between applet and servlet.
    ====================the applet code below=========================
    import java.io.*;
    import java.applet.Applet;
    import java.awt.*;
    import java.net.*;
    //I have tested that in applet get data from servlet is OK!
    //Still I will change to test in applet post data to a servlet.
    public class TestDataStreamApplet extends Applet
    String response;
    String baseurl;
    double percentUsed;
    String total;
    public void init()
    try
    java.net.URL url = new java.net.URL(getDocumentBase(),"/servlet/dataStreamEcho");
    //String currenturl=new String("http://lib.nju.edu.cn");
    java.net.URLConnection con = url.openConnection();
    //URL currentPage=getCodeBase();
    // String protocol=currentPage.getProtocol();
    // String host=currentPage.getHost();
    //int port=currentPage.getPort();
    // String urlSuffix="/servlet/dataStreamEcho";
    // URL url=new URL(protocol,host,port,urlSuffix);
    // URLConnection con=url.openConnection();
    con.setUseCaches(false);
    con.setDoOutput(true);
    con.setDoInput(true);
    ByteArrayOutputStream byteout = new ByteArrayOutputStream();
    PrintWriter out=new PrintWriter(byteout,true);
    String currenturl=new String("http://lib.nju.edu.cn");
    String var1=this.encodedValue(currenturl); //encode the data
    String data="currenturl="+var1;
    out.print(data);
    out.flush();
    con.setRequestProperty("Content-Length",String.valueOf(byteout.size()));
    con.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
    byteout.writeTo(con.getOutputStream());
    BufferedReader in=new BufferedReader(new InputStreamReader(con.getInputStream()));
    String line;
    while((line=in.readLine())!=null)
         System.out.println(line);
    catch (Exception e)
    e.printStackTrace();
    private String encodedValue(String rawValue)
         return(URLEncoder.encode(rawValue));
    =========================The servlet code below=====================
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;
    public class DataStreamEcho extends HttpServlet
    {public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
          res.setContentType("text/plain");
          PrintWriter out = res.getWriter();
          Runtime rt = Runtime.getRuntime();
          out.println(rt.freeMemory());
          out.println(rt.totalMemory());
          response.setContentType("text/html; charset=GBK");     
          request.setCharacterEncoding("GBK");
          PrintWriter out = response.getWriter();
          HttpSession session=request.getSession();
          ServletContext application=this.getServletContext();
          String currenturl=(String)session.getAttribute("currenturl");
          out.print(currenturl);
    =============================================================
    I have done up,but I found the program don't run as I have thought.
    Can you help me to find where is wrong?Very thank!

    You are trying to pass the current URL to the servlet
    from the applet, right?
    Well, what I put was correct. Your servlet code is
    trying to read some information from session data.
    request.getInputStream() is not the IP address of
    anything...see
    http://java.sun.com/products/servlet/2.2/javadoc/javax
    servlet/ServletRequest.html#getInputStream()
    Please read
    http://www.j-nine.com/pubs/applet2servlet/Applet2Servle
    .htmlNo,you all don't understand I.
    I want to send an Object to the server from a applet on a client.not url only.I maybe want to send a JPEG file instead.
    All I want is how to communicate with a servlet from an applet,send message to servlet from client's applet.
    for example,Now I have a method get the desktop picture of my client .and I want to send it to a server with a servlet to done it.How can I write the applet and servlet program?
    Now my program is down,But can only do string,can't not done Object yet.Can anyone help me?
    =======================applet=============================
    public void init()
    try
    java.net.URL url = new java.net.URL(getDocumentBase(),"/servlet/dataStreamEcho");
    //String currenturl=new String("http://lib.nju.edu.cn");
    java.net.URLConnection con = url.openConnection();
    //URL currentPage=getCodeBase();
    // String protocol=currentPage.getProtocol();
    // String host=currentPage.getHost();
    //int port=currentPage.getPort();
    // String urlSuffix="/servlet/dataStreamEcho";
    // URL url=new URL(protocol,host,port,urlSuffix);
    // URLConnection con=url.openConnection();
    con.setUseCaches(false);
    con.setDoOutput(true);
    con.setDoInput(true);
    ByteArrayOutputStream byteout = new ByteArrayOutputStream();
    PrintWriter out=new PrintWriter(byteout,true);
    String currenturl=new String("http://lib.nju.edu.cn");
    String var1=this.encodedValue(currenturl); //encode the data
    String data="currenturl="+var1;
    out.print(data);
    out.flush();
    con.setRequestProperty("Content-Length",String.valueOf(byteout.size()));
    con.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
    byteout.writeTo(con.getOutputStream());
    con.connect();
    BufferedReader in=new BufferedReader(new InputStreamReader(con.getInputStream()));
    String line;
    while((line=in.readLine())!=null)
         System.out.println(line);
    catch (Exception e)
    e.printStackTrace();
    =======================servlet=============================
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
         response.setContentType("text/html; charset=GBK");
    //request.setCharacterEncoding("GBK");
    PrintWriter out = response.getWriter();
    HttpSession session=request.getSession();
    ServletContext application=this.getServletContext();
    //String currenturl=(String)session.getAttribute("currenturl");
    String currenturl=(String)request.getParameter("currenturl");
    out.print(currenturl);
    File fileName=new File("c:\\noname.txt");
    fileName.createNewFile();
    FileOutputStream f=new FileOutputStream(fileName); //I just write the String data get from
    //applet to a file for a test.
    byte[] b=currenturl.getBytes();
    f.write(b);
    f.close();
    }

  • Popup Applet: Can we used popup applet to list records from other BC

    I have created a popup applet based on contact BC and called it from one control(ex. Add button) in my newly added applet.I am not able to see any records there in popup applet.
    Can you please suggest what is the issue or can we use popup applet to show records and select it from it.

    Hi,
    This is Siebel debugging 101.
    Have you looked at your log file to see the SQL that executed?
    Robert Ponder
    [email protected]
    770.490.2767
    www.ponderproserve.com
    Ponder Pro Serve is the recognized leader in Siebel upgrades and Siebel performance on Oracle 11g
    Edited by: Robert Ponder on Oct 21, 2010 2:01 PM

  • Can i use JSSE in my applet.?

    Hi All,
    With JSSE being a standard API in jdk1.4 i was wondering whether i can use JSSE in my applet to talk SSL to a server?. Basically i want to use SSLSocket instead of using brower's HTTPS support. Will jvm's security manager(for applet) allow me to open a SSL socket??. Please give me your thoughts on this...
    Thx a ton
    Ram

    Dear Ram
    You can't use directly. You have to sign your applet to use JSSE. As it requires to excess system settings which are not fisible if the applets are not signed.
    Hence to use it in applets jyust sign the applet and then you can do it.
    Good luck

  • Can we use applets as user interfaces with sockets, RMI and J2EE

    Dear Sir or Madam,
    Since I am a TA for software architecture class, some one ask me the following question: I think the answer is "No" based on the document on http://java.sun.com/sfaq/
    How I answer the quesions? Looking forward your help!!!
    1.You may have 2 applets and 2 html files. One applet with one html file may stay at a client PC and run on this PC, and the other applet with the other html file may stay at a server PC and run on this PC. In this case, all the applets are run locally.
    2.Could applets works with sockets, RMI and J2EE?
    3.Can we use applets as user interfaces with sockets, RMI and J2EE?
    Thank you very much!
    Best regards,
    Jing

    The scenario you paint doesn't quite make sense. The "server PC" wouldn't be running an applet, normally, since applets are by definition in a web browser page, and most likely involve user interaction, and "server processes" generally are done without user interaction.
    The security rules around applets are that -- by default -- applets can connect with sockets ONLY to the server from whence the applet was loaded. RMI uses sockets (J2EE is too broad a spec) and hence RMI calls would also be limited to the server from whence the applet was loaded. Within that limitation, an applet could open all the sockets it wants, so long as they are all on the server from whence the applet was loaded.
    If you want two applets on two different systems to communicate with each other, the simplest way is to have them rendevous through a server process on the server(s) from whence each applet was loaded. Maybe it's PC-a <-> server-a <-> server-b <-> PC-b ...? Or maybe PC-a and PC-b both are talking to the same server.
    The limitation is rooted in the security subsystem. You can specify a policy file and override anything in the security subsystem. That does mean signing the applet and then cajoling the user into agreeing to grant greater levels of security than the default. In such a case you can open sockets more broadly and then PC-a could talk directly to PC-b without going through any servers.
    - David

  • Can I use JCDK to install applets?

    I want to buy a reader from Gemplus.
    Can I use JCDK from sun to install applets or do I have to use some special installation software from the company that manufactures the reader (and I don't mean drivers)?

    It is possible to install the applets on the card with the help of jcdk. But it is very very difficult. For ease installation we have to buy the installation software from the card manufacturer . It is costly.

  • Can you use a debugger on a Java applet?

    I have a java applet .jar file. I'm running it through firefox. Can I use a debugger on this? if so, how?
    thanks.

    I'm assuming from the lack of response that the answer to my question is "no"?
    I have another program (findbugs from sourceforge) that wants debugging symbols. Should I need to do anything other than click the "generate debugging symbols" check box to make it compile with -g or whatever the normal option is to leave in debugging information?

  • How can I use the security package in JCOP41V2.2?

    Hi all, I'm a newbie in javacard programming. I'm trying to develop a project with RSA_signature. But I found, the exception NO_SUCH_ALGORITHM will be thrown out when I new an instance of KeyPair.
    My java file Temp_1.java following:
    package temp;
    import javacard.framework.Applet;
    import javacard.framework.ISO7816;
    import javacard.framework.ISOException;
    import javacard.framework.APDU;
    import javacard.security.*;
    * @author lujj
    public class Temp_1 extends Applet {
    KeyPair myKeyPair = null;
         public static void install(byte[] bArray, short bOffset, byte bLength) {
              // GP-compliant JavaCard applet registration
              new Temp_1().register(bArray, (short) (bOffset + 1), bArray[bOffset]);
         public void process(APDU apdu) throws ISOException{
              // Good practice: Return 9000 on SELECT
              if (selectingApplet()) {
                   return;
              byte[] buf = apdu.getBuffer();
              if(buf[ISO7816.OFFSET_CLA] == (byte)0xEE)
                   try
                        myKeyPair = new KeyPair(KeyPair.ALG_RSA, KeyBuilder.LENGTH_RSA_1024);
                   catch(CryptoException e)
                        ISOException.throwIt((short)(0x6F00+e.getReason()));                    
                   return;
              switch (buf[ISO7816.OFFSET_INS]) {
              case (byte) 0x00:
                   break;
              default:
                   // good practice: If you don't know the INStruction, say so:
                   ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
    This package can be upload and the applet can be installed successfully.
    But if I send the apdu "EE 00 00 00 00" after selected the applet, "6F 03" will be returned.
    Is there anyone can help me? Thanks a lot.

    Thank you so much~
    Actually, it's only an applet for test. I cannot get the error code if I new the KeyPair in install function or Applet construct function. It will return "6A 80" when install the applet.
    And, I found that it support few algorithm. For example, it does not support ALG_DES_MAC4_ISO9797_M2,etc. Is there anything I can do if I want to use the algorithm? Shall I rewrite security package by myself?
    5555, security package is the standard package in JAVACARD API 2.1.1.

Maybe you are looking for