Logo 
Search:

Java Articles

Submit Article
Home » Articles » Java » Remote Method InvocationRSS Feeds

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 sent

Posted By: Adeline Fischer     Category: Java     Views: 7033

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 RMI application for doing this.

Code for 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 sent in Java

---------------------------------------------------------------------------------
                POLICY File
---------------------------------------------------------------------------------

grant 
{
    permission java.net.SocketPermission "*:1024-65535",
        "connect,accept";
    permission java.io.FilePermission
        "C:\Sarita\Sem-5\\CORBA\\RMIAsign\\Prac-5\\-", "read";
        
};


---------------------------------------------------------------------------------
                DecodeServer.java
---------------------------------------------------------------------------------

import java.rmi.Naming;
import java.rmi.server.UnicastRemoteObject;
import java.rmi.RMISecurityManager;
import java.rmi.RemoteException;

import java.util.Properties;
import java.util.Date;
import java.util.Calendar;
import java.io.*;
import java.util.*;

import java.rmi.*;

interface DecodeInterface extends Remote 
{
    public String getDecode(String str) throws RemoteException;
}


publicclass DecodeServer extends UnicastRemoteObject implements DecodeInterface 
{
    public DecodeServer() throws RemoteException 
    {
        super();
    }
    
    public String getDecode(String s) throws RemoteException 
    {
        char str[] = s.toCharArray();
        char str1[] = newchar[20];

        for(int i=0;i<str.length;i++)
        {
            if(str[i] != ' ')
            {
                str1[i] = str[i];
                str1[i] -= 1;
            }
            else
            {
                str1[i] = str[i];
            }
        }
        
        String dstr = new String(str1);
        
        Calendar cal = Calendar.getInstance();

        String arr[] = new String[10];
        StringTokenizer st = new StringTokenizer(dstr);
        int i = 0,cnt=0;
        while(st.hasMoreTokens())
        {
            arr[i] = st.nextToken();
            String tim = cal.get(Calendar.HOUR) + ":" + cal.get(Calendar.MINUTE) + ":" + cal.get(Calendar.SECOND);
            arr[i] = arr[i] + tim;
            cnt++;
            i++;
        }

        String ans = "";
        for(i=0;i<cnt;i++)
        {
            ans = ans + arr[i] + ' ';
        }
        
        return ans;    
    }
    
    publicstaticvoid main(String[] args) 
    {
        try 
        {
            System.setSecurityManager(new RMISecurityManager());
            
            DecodeServer strObj = new DecodeServer();
            Naming.rebind("getDecode", strObj);
            System.out.println("Ready to continue....");
        }
        catch (Exception e) {
            System.err.println(e);
        }
    }
}


---------------------------------------------------------------------------------
                DecodeClient.java
---------------------------------------------------------------------------------

import java.rmi.Naming;
import java.rmi.RMISecurityManager;
import java.io.*;
import java.util.*;

publicclass DecodeClient 
{
    publicstaticvoid main(String[] args) 
    {
        try 
        {
            System.setSecurityManager(new RMISecurityManager());
            
            DecodeInterface Obj = (DecodeInterface)Naming.lookup("getDecode");
            
            BufferedReader input=new BufferedReader(new InputStreamReader(System.in));
            System.out.println("\nEnter String : ");
            String s = input.readLine();

            input.close();
            
            char str[] = s.toCharArray();
            char str1[] = newchar[20];
            for(int i=0;i<str.length;i++)
            {
                if(str[i] != ' ')
                {
                    str1[i] = str[i];
                    str1[i] += 1;
                }
                else
                {
                    str1[i] = str[i];
                }
    
            }
            
            String estr = new String(str1);
            String result = Obj.getDecode(estr);

            System.out.println("\nThe Encrypt String is : " + estr);
            System.out.println("\n\nThe Decrypt String is : " + result);
        }
        
        catch(Exception e) 
        {
            System.err.println(e);
        }
    }
}
        
        
/*
========================================================================================
OUTPUT
========================================================================================


C:\Sarita\Home28-10\RMIAsign\Prac-5>set classpath=%classpath%;c:\Sarita\Home28-10\RM
IAsign\Prac-5

C:\Sarita\Home28-10\RMIAsign\Prac-5>javac *.java

C:\Sarita\Home28-10\RMIAsign\Prac-5>rmic DecodeServer

C:\Sarita\Home28-10\RMIAsign\Prac-5>start rmiregistry

C:\Sarita\Home28-10\RMIAsign\Prac-5>start java -Djava.rmi.server.hostname=localhos
t -Djava.security.policy=java.policy DecodeServer

C:\Sarita\Home28-10\RMIAsign\Prac-5>java -Djava.security.policy=java.policy Decode
Client localhost

Enter String :
gujarat law society

The Encrypt String is : hvkbsbu mbx tpdjfuz


The Decrypt String is : gujarat10:30:31 law10:30:31 society10:30:31

C:\Sarita\Home28-10\RMIAsign\Prac-5>

*/
  
Share: 



Adeline Fischer
Adeline Fischer author of 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 sent is from Frankfurt, Germany.
 
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!