Java Lab Report Five: Java Network programming and security

Source: Internet
Author: User
Tags using git

Java Lab Report Five: Java Network programming and security

20135315 Song Ning

First, the contents of the experiment

1. Master the socket program writing;

2. Mastering the use of cryptographic technology;

3. Design a secure transmission system.

Second, the experimental steps

1. Secure transmission based on Java sockets

2. Implementation of client and server based on TCP, pair programming one person is responsible for the client, one person is responsible for the server

3. Using Git for version control

4. Select the symmetric algorithm for data encryption and decryption.

5. Select the asymmetric algorithm to distribute the key for the symmetric encryption key.

6. Select the appropriate hash algorithm for integrity verification.

7. Select the appropriate algorithm to sign/verify the hash value.

Third, design ideas

My trooped partner is Lu Chang: http://www.cnblogs.com/bonjourvivi/p/4565004.html

1. I am responsible for the part of the server, enter the clear text "Hello world!" in the client program "Then use the random key generator to generate the Des Key, through the key extension, the extended key application IO stream is stored in the file Keykb1.dat, and the output extension key is printed.

            String s= "Hello world!";                        Keygenerator kg=keygenerator.getinstance ("Desede");            Kg.init (168);             Secretkey K=kg.generatekey ();            Byte[] kb=k.getencoded ();            FileOutputStream  fk=new fileoutputstream ("Keykb1.dat");            Fk.write (KB);            for (int i=0;i<kb.length;i++) {                 System.out.print (kb[i]+ ",");//Print extension key            }

2. Encrypt the plaintext and print the ciphertext in UTF8 encoded form

Cipher cp=cipher.getinstance ("Desede");            Cp.init (Cipher.encrypt_mode, k);            Byte ptext[]=s.getbytes ("UTF8");            for (int i=0;i<ptext.length;i++) {                System.out.print (ptext[i]+ ",");            }                        System.out.println ("");            Byte ctext[]=cp.dofinal (ptext);            for (int i=0;i<ctext.length;i++) {                 System.out.print (Ctext[i] + ",");            }

3. Pass the ciphertext to the server

            FileOutputStream f2=new FileOutputStream ("SEnc.dat");            F2.write (Ctext);

4. The client takes advantage of the server's public key to pass the key encryption to the server

FileInputStream f=new FileInputStream ("Skey_rsa_pub.dat");            ObjectInputStream b=new ObjectInputStream (f);            Rsapublickey  pbk= (Rsapublickey) b.readobject ();            BigInteger e=pbk.getpublicexponent ();            BigInteger N=pbk.getmodulus ();            System.out.println ("e=" +e);            System.out.println ("n=" +n);            Byte ptext1[]=s.getbytes ("UTF8");            BigInteger m=new BigInteger (PTEXT1);            BigInteger C=m.modpow (e,n);            System.out.println ("c=" +c);            String cs=c.tostring ();            BufferedWriter out1=               New BufferedWriter (New OutputStreamWriter (                new FileOutputStream ("Enc_rsa.dat"));            Out1.write (Cs,0,cs.length ());            Out1.close ();

9. The client uses the hash function to encrypt the plaintext, passing the hash value of the plaintext to the ciphertext via IO.

String x=s;
             MessageDigest md5=messagedigest.getinstance ("MD5");             Md5.update (X.getbytes ());             byte smd5[]=md5.digest ();             String result= "";             for (int i=0; i<smd5.length; i++) {                result+=integer.tohexstring (0x000000ff & Smd5[i]) |                     0XFFFFFF00). substring (6);             }             SYSTEM.OUT.PRINTLN (result);
        OUT.PRINTLN (result);

Iv. Results of the experiment

Client

V. Problems encountered

Two people to test, the server and the client has successfully connected, but the server does not display the results, when they are connected, the server results will appear, but will be overwritten by the client results, but can quickly intercept the results, and the results are correct.

Vi. Solutions

The encryption and decryption of data is transmitted on a single computer.

Vii. Time of statistics

code implementation

steps

time-consuming

percent

Demand analysis

 3h

 27.3%

design

 1h 9.1%
 2h 18.2%

test

 4h 36.4%

Analysis summary

 1h  9.1%

Java Lab report Five: Java network programming and security

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.