Use a private key to decrypt this document, which is the only key that can decrypt and does not pass through the network. Upymmetric algorithm algorithm calculation is much more expensive and slow. So we don't want to use asymmetric algorithms to encrypt all information in the online dialogue. Instead, we use the symmetric algorithm. In the following example we use asymmetric encryption to encrypt the symmetric key. Then use the symmetric algorithm to encrypt. This work mode is this work mode. An example is a TCP program divided into server-side and clients. The server-side workflow is: receive public keys from the client. Use the public key to encrypt the symmetric key used in the future. Send the encrypted symmetric key to the client. Send information using the symmetric key encryption to the client. code show as below:
namespace com.billdawson.crypto {public class CryptoServer {private const int RSA_KEY_SIZE_BITS = 1024; private const int RSA_KEY_SIZE_BYTES = 252; private const int TDES_KEY_SIZE_BITS = 192; public static void Main (string [] args) {int port; string msg; TcpListener Listener; tcpclient client; symmetricalgorithm symm; rsacryptoserviceProvider rsa; // Get port Try {port = int32.parse (args [0]); msg = args [1];} catCh {console.writeline (usage); return;} / / Establish monitor try {listener = new TCPListener (port); listener.Start (); console.writeline ("Listening on Port {0} ...", port); client = listener.accepttcpclient (); console.writeline "Connection ...");} catch (Exception E) {console.writeline (E.MESSAGE); console.writeline (E.STACKTRACE); return;} try {r = new} tryptoserviceProvider (); rsa.keysize = RSA_KEY_SIZE_BITS; / / Get Client Public Keys Rsa.importParameters (SYMM = New TripESCRYPTOSERVICEPROVIDER (); Symm.keysize = TDES_KEY_SIZE_BITS;