//Main constructor public BooksEntityApp(string cryptoKey) : this() { var cryptoService = this.GetService <IEncryptionService>(); //created in other constructor 'this()' var cryptoBytes = HexUtil.HexToByteArray(cryptoKey); cryptoService.AddChannel(cryptoBytes); //sets up default unnamed channel }
public BooksEntityApp() : base("BookStore", CurrentVersion) { //Areas var booksArea = this.AddArea("books"); var infoArea = this.AddArea("info"); var loginArea = this.AddArea("login"); //main module MainModule = new BooksModule(booksArea); //Standard modules var dbInfoModule = new DbInfoModule(infoArea); //Job exec module - disabled for now //var jobExecModule = new Modules.JobExecution.JobExecutionModule(booksArea); // LoginModule var loginStt = new LoginModuleSettings(passwordExpirationPeriod: TimeSpan.FromDays(180)); loginStt.RequiredPasswordStrength = PasswordStrength.Medium; loginStt.DefaultEmailFrom = "*****@*****.**"; var loginModule = new LoginModule(loginArea, loginStt); // Setup encrypted data module. var encrModule = new EncryptedDataModule(booksArea); // Use TestGenerateCryptoKeys test in BasicTests project to generate // and print crypto keys for all algorithms. var cryptoKey = "8E487AD4C490AC43DF15D33AB654E5A222A02C9C904BC51E48C4FE5B7D86F90A"; var cryptoBytes = HexUtil.HexToByteArray(cryptoKey); encrModule.AddChannel(cryptoBytes); //creates default channel Instance = this; }
public static string Decrypt(string value, string purpose = "Generic") { var bytes = HexUtil.HexToByteArray(value); var textBytes = MachineKey.Unprotect(bytes, purpose); var result = Encoding.Unicode.GetString(textBytes); return(result); }
private bool InitApp() { Application.ThreadException += Application_ThreadException; try { var serviceURl = ConfigurationManager.AppSettings.Get("serviceUrl"); _app = new OAuthEntityApp(serviceURl); _app.Init(); // Get IOAuthClientService and hook to it's Redirected event - to get notified when user hits "Allow" _service = _app.GetService <IOAuthClientService>(); _service.Redirected += OAuthClientService_Redirected; //Setup default encryption channel - we store OAuth data encrypted var cryptoKey = ConfigurationManager.AppSettings.Get("CryptoKey"); var encrService = _app.GetService <Vita.Modules.EncryptedData.IEncryptionService>(); encrService.AddChannel(HexUtil.HexToByteArray(cryptoKey)); //Connect to db var connString = ConfigurationManager.AppSettings.Get("MsSqlConnectionString"); if (!CheckConnection(connString)) { return(false); } var dbSettings = new DbSettings(new MsSqlDbDriver(), MsSqlDbDriver.DefaultMsSqlDbOptions, connString); _app.ConnectTo(dbSettings); //Start local web server to handle redirects back from OAuth server, after user approves access StartWebService(serviceURl); // Hook to global error log, to show exception when it happens in Redirect controller var errLog = _app.GetService <IErrorLogService>(); errLog.ErrorLogged += ErrLog_ErrorLogged; //Just for ease of debugging this app, update servers definitions in database var session = OpenSession(); Vita.Modules.OAuthClient.OAuthServers.CreateUpdatePopularServers(session); session.SaveChanges(); return(true); } catch (Exception ex) { Log(ex.ToLogString()); MessageBox.Show(ex.Message, "Error"); return(false); } }