Java Fifth Test-20165104 Meng Fanbin

Source: Internet
Author: User
Tags object serialization

Experiment five network programming and security task a knowledge summary
    • DC Operator:
    • +: Eject W1 and W2 in turn, press the W2+W1 stack. Precision is the result value precision
    • -: Eject W1 and W2 in turn, press the W2-W1 stack
    • *: Eject W1 and W2 in turn, press the W2W1 stack. Precision is the result value precision and the larger value in precision
    • /: Eject W1 and W2 in turn, press the W2/W1 stack. Accuracy of precision
    • %: Eject W1 and W2 in turn, press the W2-W2/W1*W1 stack
    • Implement the suffix expression pseudo-code:
    • Set an operand stack to start the stack empty;
    • From left to right scan suffix expression, encountered operand, into the stack;
    • In the event of an operator, exit two elements from the stack, exit to the right of the operator, and exit to the left of the operator, and the result of the operation is then put into the stack until the suffix expression is scanned.
    • Postfix-type pseudo-code is obtained by infix:
    • Set up a stack, storing operators, the first stack is empty;
    • From left to right scan infix, if encountered operand, direct output, and output a space as two operand separator;
    • If the operator is encountered, compared to the top of the stack, the stack is higher than the top level, otherwise exit the top element of the stack and output, and then output a space for the delimiter;
    • If you encounter an opening parenthesis, enter the stack, and if you encounter a closing parenthesis, exit the stack until you exit the left parenthesis.
    • When the stack becomes empty, the result of the output is the suffix expression.

      Experimental results

Task two Knowledge summary
    • Sockets are TCP protocol-based network communication
    • Client sockets
      • Object Creation method: using the Socket class
      • Socket construction Method: Socket (String host,int port)
    • ServerSocket object and server-side sockets
      • Construction method: ServerSocket (int port)
      • Use the method accept () to connect the client socket to the server-side socket
    • Sockets use the Close () method to close a socket connection after communication is complete
    • Multithreading Technology
    • When a client-side socket is received by the server, a thread is started that is dedicated to the customer service

      Experimental results

Task Three Knowledge Summary
    • "DES" is currently the most commonly used symmetric encryption algorithm
    • Initialize key generator kg.init(168) (key length must be 56 bits)
    • Generate keySecretKey k=kg.generateKey( )
    • Storing keys in a file by object serialization
      • FileOutputStream f=new FileOutputStream("key1.dat")
      • ObjectOutputStream b=new ObjectOutputStream(f)
      • b.writeObject(k)

        Experimental results

Task Four Knowledge summary
    • The DH algorithm is based on the DH public key and the private key, A and B share the key, A and B each generate DH public key and private key, public key publicity and private keys are kept secret. This example describes how to create and deploy a DH public key and a private key in Java so that later sections can use it to create a shared secret.
    • To KeyPairGenerator create a DH public and private key using a class
      Create key Contract object: KeyAgreement ka=KeyAgreement.getInstance("DH") ;
    • Initialize the key contract object: ka.init(prk) ;
    • Execute key contract: ka.doPhase(pbk,true) ;
    • Generate shared information: byte[ ] sb=ka.generateSecret() ;

      Experimental results

Task Five Knowledge Summary
    • Java Digest Algorithm-MD5
    • java.securityThe classes in the package MessageDigest provide a way to calculate the message digest
    • To generate a MessageDigest object:
      MessageDigest m=MessageDigest.getInstance("MD5");
    • Pass in a string that needs to be evaluated:
      m.update(x.getBytes("UTF8" )); (x is a string that needs to be evaluated, the parameter that is passed in by update is a byte type or an array of byte types, and for strings you need to use the GetBytes () method to generate an array of strings.) )
    • To calculate the message digest:
      byte s[ ]=m.digest( ); (The Digest () method that executes the MessageDigest object completes the calculation, and the result of the calculation is returned by an array of byte types.) )

      Experimental results

Java Fifth Test-20165104 Meng Fanbin

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.