public string getUpdates(string token, string url) { string status = ""; string json = JSON.getContractUpdate(token); string key = Cryptography.randomString(32); string iv = Cryptography.randomString(32); string encryptedContent = Cryptography.encryptRJ256(json, key, iv); string sendData = encryptedContent + key + iv; Dictionary <string, string> data = new Dictionary <string, string>(); data.Add("CTT", sendData); string webResponse = HttpComm.httpPostData(data, url); if (webResponse.Length <= 6) { status = HttpComm.treatHttpError(webResponse, "UCT"); } else { if (this.lastModified != this.lastModifiedWeb) { status = this.updateContractData(webResponse); } else { status = "OK"; } } return(status); }
public string getConfigs(string token) { string status = "OK"; string json = JSON.getConfigUpdate(token); string key = Cryptography.randomString(32); string iv = Cryptography.randomString(32); string encryptedContent = Cryptography.encryptRJ256(json, key, iv); string sendData = encryptedContent + key + iv; Dictionary <string, string> data = new Dictionary <string, string>(); data.Add("CTT", sendData); string webResponse = HttpComm.httpPostData(data, this.consultGateway); if (webResponse.Length <= 6) { status = HttpComm.treatHttpError(webResponse, "CCF"); } else { string encryptedData = ""; string decodeKey = webResponse.Substring(0, 32); string decodeIv = webResponse.Substring(webResponse.Length - 32); int keyIndex = webResponse.IndexOf(decodeKey); encryptedData = webResponse.Remove(keyIndex, decodeKey.Length); int ivIndex = encryptedData.IndexOf(decodeIv); encryptedData = encryptedData.Remove(ivIndex, decodeIv.Length); string configData = Cryptography.decryptRJ256(encryptedData, decodeKey, decodeIv); Config c = new Config(); c = JSON.decodeConfig(configData); if (c.lastModified > this.lastModified) { this.consultGateway = c.consultGateway; this.threadSleep = c.threadSleep; this.lastModified = c.lastModified; try { this.saveConfigs(); } catch (Exception e) { status = "Impossível salvar as configurações"; } } } return(status); }
public static string newFileUploaded(string token, string key, string file, string url) { string status = "OK"; file = file.Replace("\\", "#"); string[] filePath = file.Split('#'); string json = JSON.encodeFileUploadLog("NUF", token, key, filePath[filePath.Length - 1]); string encryptKey = Cryptography.randomString(32); string encryptIv = Cryptography.randomString(32); string encryptedContent = Cryptography.encryptRJ256(json, encryptKey, encryptIv); string sendData = encryptedContent + encryptKey + encryptIv; Dictionary <string, string> data = new Dictionary <string, string>(); data.Add("CTT", sendData); string webResponse = HttpComm.httpPostData(data, url); if (webResponse.Length <= 6) { status = HttpComm.treatHttpError(webResponse, "NUF"); } else { string encryptedData = ""; string decodeKey = webResponse.Substring(0, 32); string decodeIv = webResponse.Substring(webResponse.Length - 32); int keyIndex = webResponse.IndexOf(decodeKey); encryptedData = webResponse.Remove(keyIndex, decodeKey.Length); int ivIndex = encryptedData.IndexOf(decodeIv); encryptedData = encryptedData.Remove(ivIndex, decodeIv.Length); string logData = Cryptography.decryptRJ256(encryptedData, decodeKey, decodeIv); status = JSON.decodeUploadLog(logData); } return(status); }
private void proccessLogin() { this.configs = new Config(); this.updateDialogLabel("Carregando configurações"); string status = this.configs.loadConfigs(); if (status.Equals("OK")) { this.httpFunc = "LGN"; if (loginErrorLabel.InvokeRequired) { loginErrorLabel.Invoke(new MethodInvoker(delegate { loginErrorLabel.Text = "Autenticando usuário"; })); } string user = username.Text; string pass = password.Text; byte[] keyBytes = Encoding.UTF8.GetBytes(this.hashKey); byte[] passBytes = Encoding.UTF8.GetBytes(pass); var md5 = new HMACMD5(keyBytes); byte[] hashedBytesPass = md5.ComputeHash(passBytes); string md5Pass = BitConverter.ToString(hashedBytesPass).Replace("-", "").ToLower(); Dictionary <string, string> fields = new Dictionary <string, string>(); fields.Add("FNC", this.httpFunc); fields.Add("USR", user); fields.Add("PWD", md5Pass); string json = this.generateJson(fields); string randomKey = Cryptography.randomString(32); string randomIV = Cryptography.randomString(32); string encryptedData = Cryptography.encryptRJ256(json, randomKey, randomIV); encryptedData += randomKey; encryptedData += randomIV; Dictionary <string, string> sendData = new Dictionary <string, string>(); sendData.Add("CTT", encryptedData); string webResponse = HttpComm.httpPostData(sendData, this.configs.consultGateway); if (webResponse.Length <= 6) { string message = HttpComm.treatHttpError(webResponse, this.httpFunc); this.updateDialogLabel(message); } else { this.performLogin(webResponse); } } else { this.updateDialogLabel(status); } }