Fourth Java Lab Report

Source: Internet
Author: User
Tags stdin lenovo

Beijing Institute of Electronic Technology (BESTI)

Lab Report

Course: Java class: 1353 Name: Guo Haoxue No.: 20135327

Score: Instructor: Lou Jia Peng Experimental Date: 2015.6.9

Experiment level: Preview degree: Experiment time: 15:30~18:00

Instrument Group: 20 Compulsory/elective: Elective experiment number: 04

Experiment Name: Network programming and security

Experimental purposes and requirements:

1. Mastering the Java Network programming method;

2. Master the method of Java security programming;

3. Can be used in a comprehensive range of technologies.

Experimental instrument:

Name

Model

Number

Lenovo

V480

1

Lenovo YOga 13 1

Statistics for PSP (Personal software Process) time

Steps

Time-consuming (min)

Percentage

Demand analysis

10

4.17%

Design

60

25%

Code implementation

120

50%

Test

30

12.5%

Analysis Summary

20

8.33%

First, experiment contents and steps

Lab Staff:

Client: 20135327 Guo Hao

server:20135329 Li Haiyin http://www.cnblogs.com/haikong/

Experimental content:

1 Writing network communication programs (TCP-based)

2 Encrypt the communication content using the Symmetric DES encryption algorithm

3 using asymmetric algorithms to distribute the keys used in symmetric encryption

4 Summary calculation and verification of the communication content

5 Other security measures

Experimental steps:

1. Client-side Message des encryption (using RSA public key to encrypt des keys)

2. The server accepts the information and decrypts it (using the RSA private key)

3. Verifying Information integrity

Experiment Code:

Import java.math.*;

Import java.net.*;
Import Java.security.Key;

Import java.io.*;

Import Javax.crypto.Cipher;

public class Client {

public static void Main (String srgs[]) {

try {

Socket socket = new Socket ("172.30.113.2", 4421);

BufferedReader in = new BufferedReader (New InputStreamReader (Socket.getinputstream ()));


PrintWriter out = new PrintWriter (new BufferedWriter (New OutputStreamWriter (Socket.getoutputstream ())), true);

BufferedReader stdin = new BufferedReader (new InputStreamReader (system.in));

System.out.print ("Please lose the data sent:");

String s = stdin.readline ();

String cs = new SEnc (). ENC (s);

SYSTEM.OUT.PRINTLN ("Ciphertext sent to the server:" + cs);


String ck = new Enc_rsa (). ENC (s);

SYSTEM.OUT.PRINTLN ("The encryption key sent to the server is:" + ck);

String result = Digestcalc.hash (s);

System.out.println ("MD5:" + result);

Out.println (CK);

OUT.PRINTLN (CS);

OUT.PRINTLN (result);

} catch (Exception e) {

System.out.println (e);

} finally {

}

}

}

Experiment:

Second, the problems encountered in the experiment and the solutions

1. Send after des encrypted ciphertext is the way to convert it to a string, where the client is using the ToString () function, the server is using the GetBytes () function, after the transmission of ciphertext error. In the last discussion, binary to hexadecimal output cipher text is used. The code is as follows:

public static String bytestohexstring (byte[] src) {
StringBuilder StringBuilder = new StringBuilder ("");
if (src = = NULL | | src.length <= 0) {
return null;
}
for (int i = 0; i < src.length; i++) {
int v = src[i] & 0xFF;
String HV = integer.tohexstring (v);
if (Hv.length () < 2) {
Stringbuilder.append (0);
}
Stringbuilder.append (HV);
}
return stringbuilder.tostring ();
}

2. Two computers have been unable to connect

In the lab we started with our own IPV4 address from the bedroom LAN and then showed the connection timeout.

We think it may be that the two computers are not in the same network without a successful link, try to use a computer to connect to the network and WiFi to another computer, and then connect two computers again, finally connected successfully.

Do not know why, it may be because of the local area network!

Fourth Java Lab Report

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.