private async void LoadDataClick(object sender, RoutedEventArgs e) { try { RSACryptoServiceProvider rsa; WorkHistroySmartContract workHistroySmartContract = new WorkHistroySmartContract(); using (rsa = new RSACryptoServiceProvider(Consts.RSA_KEY_LENGTH)) { try { RSACryptoServiceProviderExtensions.FromXmlString(rsa, File.ReadAllText(_xmlStringPath)); DataSubjectSharer dataSubjectSharer = new DataSubjectSharer(); dataSubjectSharer.WorkHistroySmartContract = workHistroySmartContract; dataSubjectSharer.RSA = rsa; workHistroySmartContract.LoadContract(AddressEntry.Text); string decryptedData = await dataSubjectSharer.DecryptDataFromContract(); DataOutput.Text = decryptedData; } finally { rsa.PersistKeyInCsp = false; } } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }
public byte[] Encrypt(string publicKey, string plain) { byte[] encrypted; using (var rsa = new RSACryptoServiceProvider(2048)) { rsa.PersistKeyInCsp = false; RSACryptoServiceProviderExtensions.FromXmlString(rsa, publicKey); encrypted = rsa.Encrypt(Encoding.UTF8.GetBytes(plain), true); } return(encrypted); }
public string Decrypt(string privateKey, byte[] encrypted) { byte[] decrypted; using (var rsa = new RSACryptoServiceProvider(2048)) { rsa.PersistKeyInCsp = false; RSACryptoServiceProviderExtensions.FromXmlString(rsa, privateKey); //rsa.FromXmlString(privateKey); decrypted = rsa.Decrypt(encrypted, true); } return(Encoding.UTF8.GetString(decrypted)); }
public static async Task BenchmarkWorkHistoryBundleCreation(Queue <string> inputQue) { WorkHistroySmartContract workHistroySmartContract = new WorkHistroySmartContract(); RSACryptoServiceProvider rsa; DataSubjectSharer dataSubjectSharer = new DataSubjectSharer { WorkHistroySmartContract = workHistroySmartContract, }; using (rsa = new RSACryptoServiceProvider(Consts.RSA_KEY_LENGTH)) { try { dataSubjectSharer.RSA = rsa; string xmlString = new StreamReader("privatePaul.xml").ReadToEnd(); RSACryptoServiceProviderExtensions.FromXmlString(rsa, xmlString); DataBundle dataBundle = new DataBundle(); List <Entry> workHistory = await dataSubjectSharer.GetAllWorkHistory(); string input; do { input = inputQue.Dequeue(); try { int i = Int32.Parse(input) - 1; dataBundle.WorkHistory.Add(workHistory[i]); } catch (Exception e) { } } while (input != "done"); while ((input = inputQue.Dequeue()) != "done") { dataBundle.Referees.Add(await Entry.ReadEntry(input)); } input = inputQue.Dequeue(); Utils.ExportToJsonFile(input, dataBundle); } finally { rsa.PersistKeyInCsp = false; } } }
private static async Task EmpMenu(string[] args) { WorkHistroySmartContract workHistroySmartContract = new WorkHistroySmartContract(); RSACryptoServiceProvider rsa; DataSubjectSharer dataSubjectSharer = new DataSubjectSharer { WorkHistroySmartContract = workHistroySmartContract, }; using (rsa = new RSACryptoServiceProvider(Consts.RSA_KEY_LENGTH)) { try { dataSubjectSharer.RSA = rsa; string xmlString = new StreamReader(args[1]).ReadToEnd(); RSACryptoServiceProviderExtensions.FromXmlString(rsa, xmlString); switch (args[0].ToLower()) { case "add": dataSubjectSharer.AddAddress(args[2]); dataSubjectSharer.SaveChangesToAddresses(); break; case "craete": await CreateWorkHistoryBundle(dataSubjectSharer); break; case "export": await ExportEntry(dataSubjectSharer); break; } } finally { rsa.PersistKeyInCsp = false; } } }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, MimirContext db) { if (env.IsDevelopment()) { log.Info("LittleC is a potato!"); app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/error"); } // Load logic configs. log.Info("Loading logic configs."); try { Program.ServerName = (from o in db.Options where o.Option == "ServerName" select o.Value).First(); if ((from o in db.Options where o.Option == "PrivateKeyXml" select o.Value).First() == string.Empty) { SignatureWorker.GenKey(db); } RSACryptoServiceProviderExtensions.FromXmlString(Program.PrivateKeyProvider, (from o in db.Options where o.Option == "PrivateKeyXml" select o.Value).First()); Program.PublicKey = (from o in db.Options where o.Option == "PublicKey" select o.Value).First(); Program.ServerDomain = (from o in db.Options where o.Option == "ServerDomain" select o.Value).First(); int.TryParse((from o in db.Options where o.Option == "SecurityLoginTryTimes" select o.Value).First(), out Program.SecurityLoginTryTimes); bool.TryParse((from o in db.Options where o.Option == "IsEnableMultiProfiles" select o.Value).First(), out Program.IsEnableMultiProfiles); int.TryParse((from o in db.Options where o.Option == "MaxTokensPerProfile" select o.Value).First(), out Program.MaxTokensPerProfile); int.TryParse((from o in db.Options where o.Option == "TokensExpireDaysLimit" select o.Value).First(), out Program.TokensExpireDaysLimit); long.TryParse((from o in db.Options where o.Option == "SessionsExpireSeconds" select o.Value).First(), out Program.SessionsExpireSeconds); Program.SkinDomains = (from o in db.Options where o.Option == "SkinDomains" select o.Value).First().Split(","); int.TryParse((from o in db.Options where o.Option == "MaxProfileCountPerQuery" select o.Value).First(), out Program.MaxProfileCountPerQuery); bool.TryParse((from o in db.Options where o.Option == "IsEnableLandingPage" select o.Value).First(), out Program.IsEnableLandingPage); bool.TryParse((from o in db.Options where o.Option == "IsEnableSmtp" select o.Value).First(), out Program.IsEnableSmtp); Program.SmtpDomain = (from o in db.Options where o.Option == "SmtpDomain" select o.Value).First(); int.TryParse((from o in db.Options where o.Option == "SmtpPort" select o.Value).First(), out Program.SmtpPort); Program.SmtpEmail = (from o in db.Options where o.Option == "SmtpEmail" select o.Value).First(); Program.SmtpName = (from o in db.Options where o.Option == "SmtpName" select o.Value).First(); Program.SmtpPassword = (from o in db.Options where o.Option == "SmtpPassword" select o.Value).First(); bool.TryParse((from o in db.Options where o.Option == "SmtpIsSsl" select o.Value).First(), out Program.SmtpIsSsl); int.TryParse((from o in db.Options where o.Option == "MaxProfileCountPerUser" select o.Value).First(), out Program.MaxProfileCountPerUser); bool.TryParse((from o in db.Options where o.Option == "IsHttps" select o.Value).First(), out Program.IsHttps); } catch (Exception) { log.Fatal("Bad database."); throw; } log.Info("Logic configs loaded."); app.UseSession(); //app.UseHttpsRedirection(); app.UseStaticFiles(new StaticFileOptions() { ServeUnknownFileTypes = true, DefaultContentType = "image/png" }); app.Use(next => { return(async context => { context.Response.OnStarting(() => { // Add ALI. if (Program.IsHttps) { context.Response.Headers.Add("X-Authlib-Injector-API-Location", "https://" + Program.ServerDomain + "/api/"); } else { context.Response.Headers.Add("X-Authlib-Injector-API-Location", "http://" + Program.ServerDomain + "/api/"); } context.Response.Headers["Server"] = "Mimir"; context.Response.Headers.Add("Author", "Romonov"); return Task.CompletedTask; }); await next(context); }); }); app.UseMvc(routes => { routes.MapRoute( name: "yggdrasil_sessionserver_get_profile", template: "api/sessionserver/session/minecraft/profile/{uuid}", defaults: new { controller = "SessionServer", action = "Profile" }); routes.MapRoute( name: "yggdrasil_sessionserver_join", template: "api/sessionserver/session/minecraft/join", defaults: new { controller = "SessionServer", action = "Join" }); routes.MapRoute( name: "yggdrasil_sessionserver_has_joined", template: "api/sessionserver/session/minecraft/hasJoined", defaults: new { controller = "SessionServer", action = "HasJoined" }); routes.MapRoute( name: "yggdrasil_api_profiles_query", template: "api/api/profiles/minecraft", defaults: new { controller = "Api", action = "Profiles" }); routes.MapRoute( name: "yggdrasil_authserver", template: "api/authserver/{action}", defaults: new { controller = "AuthServer" }); routes.MapRoute( name: "yggdrasil_index", template: "api", defaults: new { controller = "Api", action = "Index" }); routes.MapRoute( name: "default", template: "{controller=Index}/{action=Index}/{id?}"); }); }