public async Task <IActionResult> OneTimeSignIn([FromBody] Credentials credentials) { Credentials hashedCredentials = new Credentials(); hashedCredentials.UniqueKey = CustomHashing.ComputeSha256Hash(credentials.UniqueKey); hashedCredentials.PrimaryKey = CustomEncryption.Encrypt(credentials.PrimaryKey, credentials.UniqueKey); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } GenericResponse <Credentials> response = new GenericResponse <Credentials>(); try { _context.Credentials.Add(hashedCredentials); await _context.SaveChangesAsync(); response.HasError = false; response.Messege = "successfull"; response.Result = hashedCredentials; response.StatusCode = 200; } catch (Exception e) { response.HasError = true; response.Messege = e.ToString(); response.Result = null; response.StatusCode = 400; } return(Ok(response)); }
/// <summary> /// /// </summary> /// <param name="CRS"></param> /// <returns></returns> public Credentials GetUser(string CRS) { if (CRS.ToUpper() == "GALILEO") { Credentials Cred = new Credentials(); try { string GalileoUserName = WebConfigurationManager.AppSettings["galileousername"]; string Test = "Amext80"; string en = CustomEncryption.Encrypt(Test); string edbpassword = WebConfigurationManager.AppSettings["galileopassword"]; Cred.PSW = CustomEncryption.Decrypt(edbpassword); Cred.User = GalileoUserName; Cred.CRS = CRS; Cred.URL = WebConfigurationManager.AppSettings["galileoURL"]; Cred.ItineraryURL = WebConfigurationManager.AppSettings["galileoItineraryURL"]; Cred.HAP = WebConfigurationManager.AppSettings["galileoHostAccessProfile"]; return(Cred); } catch (Exception e) { System.Diagnostics.Trace.WriteLine(e.Message); } } else if (CRS.ToUpper() == "DIABLO") { Credentials Cred = new Credentials(); try { string GalileoUserName = WebConfigurationManager.AppSettings["diablousername"]; string edbpassword = WebConfigurationManager.AppSettings["diablopassword"]; Cred.PSW = CustomEncryption.Decrypt(edbpassword); Cred.User = GalileoUserName; Cred.CRS = CRS; Cred.URL = "."; Cred.ItineraryURL = ""; Cred.HAP = ""; return(Cred); } catch (Exception e) { System.Diagnostics.Trace.WriteLine(e.Message); } } return(null); }
private Credentials getPrivateKey(string UniqueKey) { var password = CustomHashing.ComputeSha256Hash(UniqueKey); var model = _context.Credentials.Where(p => p.UniqueKey == password).FirstOrDefault(); if (model != null) { model.PrimaryKey = CustomEncryption.Decrypt(model.PrimaryKey, UniqueKey); } return(model); }
string GetDecryptedValue(string inputValue) { Console.WriteLine("Decrypt Method"); Console.WriteLine("Input string: {0}", inputValue); Console.WriteLine("Before calling decrypt:{0}", DateTime.Now.ToString("O")); var stopwath = new Stopwatch(); stopwath.Start(); DateTime time1 = DateTime.Now; var decodedValue = CustomEncryption.Decrypt(inputValue); stopwath.Stop(); Console.WriteLine("After calling decrypt:{0}", DateTime.Now.ToString("O")); Console.WriteLine("Ticks taken: {0}", stopwath.ElapsedTicks); Console.WriteLine("Milliseconds taken: {0}", (DateTime.Now - time1).TotalMilliseconds); Console.WriteLine("Decoded value: " + decodedValue); return(decodedValue); }
string GetEncryptedValue(string inputValue) { Console.WriteLine("Input string: {0}", inputValue); Console.WriteLine("Before calling encrypt:{0}", DateTime.Now.ToString("O")); var stopwath = new Stopwatch(); stopwath.Start(); DateTime startTime = DateTime.Now; var encodedValue = CustomEncryption.Encrypt(inputValue); stopwath.Stop(); Console.WriteLine("After calling encrypt:{0}", DateTime.Now.ToString("O")); Console.WriteLine("Ticks taken: {0}", stopwath.ElapsedTicks); Console.WriteLine("Milliseconds taken: {0}", (DateTime.Now - startTime).TotalMilliseconds); Console.WriteLine("Encoded value: " + encodedValue); Console.WriteLine(); return(encodedValue); }
/// <summary> /// GetDataSourceMySQL /// </summary> /// <returns></returns> public string GetDataSourceMySQL() { string DSN = WebConfigurationManager.AppSettings["DataSourceMySQL"]; string dbusername = WebConfigurationManager.AppSettings["dbusername"]; string edbpassword = WebConfigurationManager.AppSettings["dbpassword"]; try { if (DSN.IndexOf("{0}") != -1) { DSN = string.Format(DSN, dbusername, CustomEncryption.Decrypt(edbpassword)); } } catch (Exception e) { System.Diagnostics.Trace.WriteLine(e.Message); return(""); } return(DSN); }
public async Task <IActionResult> CreateWallet(string uniqueKey) { GenericResponse <Account> response = new GenericResponse <Account>(); Credentials model = new Credentials(); BlockChainController chainController = new BlockChainController(); try { var account = await chainController .CreateWallet(uniqueKey); model.UniqueKey = CustomHashing.ComputeSha256Hash(uniqueKey); model.PrimaryKey = CustomEncryption.Encrypt(account.PrivateKey, uniqueKey); _context.Credentials.Add(model); await _context.SaveChangesAsync(); if (account != null) { response.HasError = false; response.Messege = "Sucessfull"; response.Result = account; response.StatusCode = 200; } } catch (Exception e) { response.HasError = true; response.Messege = "unsucessfull"; response.Result = null; response.StatusCode = 400; } return(Ok(response)); }