Logo 
Search:

Java Articles

Submit Article
Home » Articles » Java » CorbaRSS Feeds

Corba program to encrypt the text that you want to send on the client side. The server side decrypts it after receiving. Append server time.

Posted By: Milind Mishra     Category: Java     Views: 3753

Encrypt the text that you want to send on the client side. The server side decrypts it after receiving. Append server time after each word in the sentence. Decrypt it and send it back to the client. Write a CORBA application for doing this.

Code for Corba program to encrypt the text that you want to send on the client side. The server side decrypts it after receiving. Append server time. in Java

// encrypt.idl

module encrypt_val
{
  interface encrypt
  {
    string getstr(instring a);
  };
};


// encrypt_client.java

import encrypt_val.*;
import org.omg.CosNaming.*;
import org.omg.CosNaming.NamingContextPackage.*;
import org.omg.CORBA.*;
import java.io.*;
import java.lang.*;
publicclass encrypt_client
{
    static encrypt encryptimpl;
    publicstaticvoid main(String args[])
    {
      try
      {
        
        String result_str,tempstr;
        ORB orb=ORB.init(args,null);
        org.omg.CORBA.Object objref=orb.resolve_initial_references("NameService");

        NamingContextExt ncref=NamingContextExtHelper.narrow(objref);

        String pathname="encrypt";
        encryptimpl=encryptHelper.narrow(ncref.resolve_str(pathname));

        BufferedReader in=new BufferedReader(new InputStreamReader(System.in));

        System.out.println("Enter string you want to send to server : ");
        tempstr=in.readLine();
        StringBuffer string1=new StringBuffer(tempstr);
    for(int i=0;i<string1.length();i++)
        {
          string1.setCharAt(i,(char)(string1.charAt(i)+2));
        }
        System.out.println("Encrypted string sent to server : "+string1);

        result_str=encryptimpl.getstr(string1.toString());

        System.out.println("Decrypted string recvd from server is as below:");
        System.out.println(result_str);

      }
      catch(Exception e)
      {
         System.out.println(e);
      }
    }

}


// encrypt_server.java

import encrypt_val.*;
import org.omg.CosNaming.*;
import org.omg.CosNaming.NamingContextPackage.*;
import org.omg.CORBA.*;
import org.omg.PortableServer.*;
import org.omg.PortableServer.POA;
import java.lang.*;
import java.util.*;
import java.text.*;
class serverimpl extends encryptPOA
{
   private ORB orb;
   publicvoid setorb(ORB orb_val)
   {
      orb=orb_val;
   }

   public String getstr(String str1)
   {
     StringBuffer strb1=new StringBuffer(str1);
     Date dateobj=new Date();
     SimpleDateFormat sdf;
     sdf=new SimpleDateFormat("hh:mm:ss");

     String datestr=sdf.format(dateobj).toString();
     datestr=" "+datestr+" ";

     for(int i=0;i<strb1.length();i++)
        {
          strb1.setCharAt(i,(char)(strb1.charAt(i)-2));
          if(strb1.charAt(i)==' ')
            {
             strb1.insert(i,datestr);
             i=i+datestr.length();
            }
       }
     return(strb1.toString());
   }
}
publicclass encrypt_server
{
   publicstaticvoid main(String args[])
   {
     try
     {
         ORB orb=ORB.init(args,null);

         org.omg.CORBA.Object objref1=orb.resolve_initial_references("RootPOA");
         POA rootpoa=POAHelper.narrow(objref1);
         rootpoa.the_POAManager().activate();

         serverimpl serverobj=new serverimpl();
         serverobj.setorb(orb);
         org.omg.CORBA.Object objref2=rootpoa.servant_to_reference(serverobj);
         encrypt href=encryptHelper.narrow(objref2);

         org.omg.CORBA.Object objref3= orb.resolve_initial_references("NameService");
         NamingContextExt ncref=NamingContextExtHelper.narrow(objref3);
         String pathname="encrypt";
         NameComponent path[]=ncref.to_name(pathname);
         ncref.rebind(path,href);


         System.out.println("server ready and waiting...");

         orb.run();

     }
     catch(Exception e)
     {
       System.out.println(e);
     }
   }


}


// Output :

E:\DIPI1\corba prgs\encrypt>java encrypt_client -ORBInitialPort 1050 -ORBInitialHost a

Enter string you want to send to server :
hi how are you
Encrypted string sent to server : jk"jqy"ctg"{qw
Decrypted string recvd from server isas below:
hi 07:15:56  how 07:15:56  are 07:15:56  you
  
Share: 



Milind Mishra
Milind Mishra author of Corba program to encrypt the text that you want to send on the client side. The server side decrypts it after receiving. Append server time. is from India.
 
View All Articles

Related Articles and Code:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!