Beispiel #1
0
        public static string CreateCommand(string signature, string input, IKeySym privateKey)
        {
            IParser <ParamArgs> parser = new CommandParser();
            ParamArgs           output = parser.Parse(input);

            if (output.Count == 0)
            {
                throw new OperationCanceledException("Could not parse command.");
            }

            Header header     = new Header(signature, "", output.Get <string>("Command"));
            string jsonHeader = Newtonsoft.Json.JsonConvert.SerializeObject(header);

            DynamicData detail = new DynamicData();

            foreach (string key in output.ToDictionary().Keys)
            {
                if (!key.Equals("Command"))
                {
                    detail.Add(key, output.Get <object>(key));
                }
            }
            string  jsonDetail = Newtonsoft.Json.JsonConvert.SerializeObject(detail.GetDictionary());
            Crypter crypter    = new Crypter(privateKey);

            string final = string.Format(Format, jsonHeader, jsonDetail);

            return(crypter.Encrypt(final));
        }
Beispiel #2
0
 public Crypter(IKeySym keySym)
 {
     if (keySym == null)
     {
         throw new ArgumentNullException("\'KeySym\' cannot be null.");
     }
     privateKey = keySym;
 }
Beispiel #3
0
 public Client(string ip, int port, IKeySym privateKey)
 {
     this.ip   = ip;
     this.port = port;
     if (privateKey == null)
     {
         throw new ArgumentNullException("privateKey");
     }
     this.privateKey = privateKey;
     tcpClient       = new TcpClient();
     crypter         = new Crypter(privateKey);
     encode          = Encoding.GetEncoding("ibm850");
     parser          = new CommandParser();
 }
Beispiel #4
0
 public Client(string ip, int port, IKeySym privateKey)
 {
     this.ip = ip;
     this.port = port;
     if (privateKey == null)
     {
         throw new ArgumentNullException("privateKey");
     }
     this.privateKey = privateKey;
     tcpClient = new TcpClient();
     crypter = new Crypter(privateKey);
     encode = Encoding.GetEncoding("ibm850");
     parser = new CommandParser(); 
 }
Beispiel #5
0
        public static string CreateCommand(string signature, string input, IKeySym privateKey)
        {
            IParser<ParamArgs> parser = new CommandParser(); 
            ParamArgs output = parser.Parse(input);
            if (output.Count == 0) throw new OperationCanceledException("Could not parse command.");

            Header header = new Header(signature, "", output.Get<string>("Command"));
            string jsonHeader = Newtonsoft.Json.JsonConvert.SerializeObject(header);

            DynamicData detail = new DynamicData();
            foreach (string key in output.ToDictionary().Keys)
            {
                if (!key.Equals("Command"))
                {
                    detail.Add(key, output.Get<object>(key));
                }
            }
            string jsonDetail = Newtonsoft.Json.JsonConvert.SerializeObject(detail.GetDictionary());
            Crypter crypter = new Crypter(privateKey);

            string final = string.Format(Format, jsonHeader, jsonDetail);
            return crypter.Encrypt(final); 
        }
Beispiel #6
0
 public TcpCommand(string hostName, int port, IKeySym publicKey)
     : base(new TcpConnection(hostName, port))
 {
     encoding = Encoding.GetEncoding("ibm850");
     base.PublicKey = publicKey;
 }
Beispiel #7
0
 public TcpCommand(IGSMConnection connection, IKeySym publicKey)
     : base(connection)
 {
     encoding = Encoding.GetEncoding("ibm850");
     base.PublicKey = publicKey;
 }
Beispiel #8
0
 public Crypter(IKeySym keySym)
 {
     if (keySym == null)
         throw new ArgumentNullException("\'KeySym\' cannot be null.");
     privateKey = keySym;
 }
Beispiel #9
0
 public TcpCommand(string hostName, int port, IKeySym publicKey)
     : base(new TcpConnection(hostName, port))
 {
     encoding       = Encoding.GetEncoding("ibm850");
     base.PublicKey = publicKey;
 }
Beispiel #10
0
 public TcpCommand(IGSMConnection connection, IKeySym publicKey)
     : base(connection)
 {
     encoding       = Encoding.GetEncoding("ibm850");
     base.PublicKey = publicKey;
 }