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; //获取端口 try { port = Int32.Parse(args[0]); msg = args[1]; } catch { Console.WriteLine(USAGE); return; } //建立监听 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 { rsa = new RSACryptoServiceProvider(); rsa.KeySize = RSA_KEY_SIZE_BITS;
// 获取客户端公共密钥 rsa.ImportParameters(getClientPublicKey(client));
symm = new TripleDESCryptoServiceProvider(); symm.KeySize = TDES_KEY_SIZE_BITS;
|