public resultClass decrypt_Token(resultClass token) { if (token == null) { token = new resultClass(); } encryptClass decrypt = get_decrypted_file(); DateTime timestamp = DateTime.MinValue; Int32 expiration = 0; token.user_name = (decrypt.user_name == null) ? String.Empty : decrypt.user_name; token.credential = (decrypt.credential == null) ? String.Empty : decrypt.credential; token.bearer_token = (decrypt.token == null) ? String.Empty : decrypt.token; Int32.TryParse(decrypt.token_expires, out expiration); token.expiration = 60; DateTime.TryParse(decrypt.token_creation, out timestamp); token.timestamp = timestamp; //Console.WriteLine(string.Format("Decrypted username: {0}", token.user_name)); //Console.WriteLine(string.Format("Decrypted credential: {0}", token.credential)); //Console.WriteLine(string.Format("Decrypted bearer_token: {0}", token.bearer_token)); //Console.WriteLine(string.Format("Decrypted token_expires: {0}", token.expiration)); //Console.WriteLine(string.Format("Decrypted token_creation: {0}", token.timestamp)); return(token); }
public void encrypt_Token(resultClass token) { encryptClass decrypt = get_decrypted_file(); decrypt.token = token.bearer_token; decrypt.token_creation = token.timestamp.ToString(); decrypt.token_expires = token.expiration.ToString(); set_encrypted_file(decrypt); return; }
public resultClass encrypt_Credentials() { if (_token == null) { _token = new resultClass(); } encryptClass decrypt = get_decrypted_file(); decrypt.user_name = _token.user_name; decrypt.credential = _token.credential; set_encrypted_file(decrypt); return(_token); }
public resultClass decrypt_Credentials() { if (_token == null) { _token = new resultClass(); } encryptClass decrypt = get_decrypted_file(); // Decrypt username & credential and print to the console _token.user_name = decrypt.user_name; _token.credential = decrypt.credential; //Console.WriteLine(string.Format("Decrypted username: {0}", token.user_name)); //Console.WriteLine(string.Format("Decrypted credential: {0}", token.credential)); return(_token); }
public bool set_encrypted_file(encryptClass encrypt) { string folder = _os.Contains("Windows") ? "\\" : "/"; try { string Json_string = Newtonsoft.Json.JsonConvert.SerializeObject(encrypt); string encrypted = _cipherService.Encrypt(Json_string); string path = _settings.CxDataFilePath + folder + _settings.CxDataFileName; File.WriteAllText(path, encrypted); return(true); } catch (Exception ex) { Console.Error.Write(ex.ToString()); return(false); } }
public encryptClass get_decrypted_file() { string folder = _os.Contains("Windows") ? "\\" : "/"; try { string path = _settings.CxDataFilePath + folder + _settings.CxDataFileName; string encrypted = File.ReadAllText(path); encryptClass encrypt = Newtonsoft.Json.JsonConvert.DeserializeObject <encryptClass>(_cipherService.Decrypt(encrypted)); return(encrypt); } catch (Exception ex) { if (_token.api_action != api_action.storeCredentials) { Console.Error.Write(ex.ToString()); } return(new encryptClass()); } }
public encryptClass get_decrypted_file() { try { if (_debug) { Console.WriteLine("Debug settings: {0} : {1}", _settings.CxDataFilePath, _settings.CxDataFileName); } string path = Path.Combine(_settings.CxDataFilePath, _settings.CxDataFileName); string encrypted = File.ReadAllText(path); encryptClass encrypt = Newtonsoft.Json.JsonConvert.DeserializeObject <encryptClass>(_cipherService.Decrypt(encrypted)); return(encrypt); } catch (Exception ex) { if (_token.api_action != api_action.storeCredentials) { Console.Error.Write(ex.ToString()); } return(new encryptClass()); } }
public bool set_encrypted_file(encryptClass encrypt) { string folder = _os.Contains("Windows") ? "\\" : "/"; try { settingClass settings = get_settings(); string Json_string = Newtonsoft.Json.JsonConvert.SerializeObject(encrypt); string encrypted = _cipherService.Encrypt(Json_string); if (_debug) { Console.WriteLine("Setting file: {0} : {1}", settings.CxDataFilePath, settings.CxDataFileName); } string path = Path.Combine(settings.CxDataFilePath, settings.CxDataFileName); File.WriteAllText(path, encrypted); return(true); } catch (Exception ex) { Console.Error.Write(ex.ToString()); return(false); } }