public void Encrypt() { using (ChoPGPEncryptDecrypt pgp = new ChoPGPEncryptDecrypt()) { using (Stream input = File.OpenRead("SampleData.txt")) { using (Stream output = File.OpenWrite("SampleData.PGP")) { pgp.Encrypt(input, output, "Sample_Pub.asc", true, false); } } } }
private MemoryStream EncryptString(string text) { using (ChoPGPEncryptDecrypt pgp = new ChoPGPEncryptDecrypt()) { MemoryStream a = new System.IO.MemoryStream(); byte[] byteArray = Encoding.UTF8.GetBytes(text); MemoryStream stream = new MemoryStream(byteArray); pgp.Encrypt(stream, a, "Sample_Pub.asc", true, false); return(a); } }
private static void Encrypt() { using (ChoPGPEncryptDecrypt pgp = new ChoPGPEncryptDecrypt()) { using (Stream input = File.OpenRead("SampleData.txt")) { using (Stream output = File.OpenWrite("SampleData.PGP")) { //pgp.CompressionAlgorithm = ChoCompressionAlgorithm.Zip; pgp.Encrypt(input, output, "Sample_Pub.asc", true, false); } } } }
public async Task <IActionResult> UploadReport() { var response = new ContentResult { StatusCode = (int)HttpStatusCode.OK, ContentType = "text/plain" }; try { var newReport = new DeviceReport(); HttpRequest request = HttpContext.Request; var xs = new XmlSerializer(newReport.GetType()); newReport = (DeviceReport) xs.Deserialize(new StringReader(await new StreamReader(request.Body).ReadToEndAsync())); if (newReport == null) { response.Content = "notstats"; return(response); } var reportV2 = new DeviceReportV2(newReport); var jsonSw = new StringWriter(); jsonSw.Write(JsonConvert.SerializeObject(reportV2, Formatting.Indented, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore })); string reportV2String = jsonSw.ToString(); jsonSw.Close(); ctx.Reports.Add(new UploadedReport(reportV2)); ctx.SaveChanges(); var pgpIn = new MemoryStream(Encoding.UTF8.GetBytes(reportV2String)); var pgpOut = new MemoryStream(); var pgp = new ChoPGPEncryptDecrypt(); pgp.Encrypt(pgpIn, pgpOut, Path.Combine(_environment.ContentRootPath ?? throw new InvalidOperationException(), "public.asc")); pgpOut.Position = 0; reportV2String = Encoding.UTF8.GetString(pgpOut.ToArray()); var message = new MimeMessage { Subject = "New device report (old version)", Body = new TextPart("plain") { Text = reportV2String } }; message.From.Add(new MailboxAddress("DiscImageChef", "*****@*****.**")); message.To.Add(new MailboxAddress("Natalia Portillo", "*****@*****.**")); using (var client = new SmtpClient()) { client.Connect("mail.claunia.com", 25, false); client.Send(message); client.Disconnect(true); } response.Content = "ok"; return(response); } // ReSharper disable once RedundantCatchClause catch { #if DEBUG if (Debugger.IsAttached) { throw; } #endif response.Content = "error"; return(response); } }
public async Task <IActionResult> UploadReportV2() { var response = new ContentResult { StatusCode = (int)HttpStatusCode.OK, ContentType = "text/plain" }; try { HttpRequest request = HttpContext.Request; var sr = new StreamReader(request.Body); string reportJson = await sr.ReadToEndAsync(); var newReport = JsonConvert.DeserializeObject <DeviceReportV2>(reportJson); if (newReport == null) { response.Content = "notstats"; return(response); } ctx.Reports.Add(new UploadedReport(newReport)); ctx.SaveChanges(); var pgpIn = new MemoryStream(Encoding.UTF8.GetBytes(reportJson)); var pgpOut = new MemoryStream(); var pgp = new ChoPGPEncryptDecrypt(); pgp.Encrypt(pgpIn, pgpOut, Path.Combine(_environment.ContentRootPath ?? throw new InvalidOperationException(), "public.asc")); pgpOut.Position = 0; reportJson = Encoding.UTF8.GetString(pgpOut.ToArray()); var message = new MimeMessage { Subject = "New device report", Body = new TextPart("plain") { Text = reportJson } }; message.From.Add(new MailboxAddress("DiscImageChef", "*****@*****.**")); message.To.Add(new MailboxAddress("Natalia Portillo", "*****@*****.**")); using (var client = new SmtpClient()) { client.Connect("mail.claunia.com", 25, false); client.Send(message); client.Disconnect(true); } response.Content = "ok"; return(response); } // ReSharper disable once RedundantCatchClause catch { #if DEBUG if (Debugger.IsAttached) { throw; } #endif response.Content = "error"; return(response); } }
public HttpResponseMessage UploadReport() { HttpResponseMessage response = new HttpResponseMessage { StatusCode = HttpStatusCode.OK }; try { DeviceReport newReport = new DeviceReport(); HttpRequest request = HttpContext.Current.Request; XmlSerializer xs = new XmlSerializer(newReport.GetType()); newReport = (DeviceReport)xs.Deserialize(request.InputStream); if (newReport == null) { response.Content = new StringContent("notstats", Encoding.UTF8, "text/plain"); return(response); } DeviceReportV2 reportV2 = new DeviceReportV2(newReport); StringWriter jsonSw = new StringWriter(); jsonSw.Write(JsonConvert.SerializeObject(reportV2, Formatting.Indented, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore })); string reportV2String = jsonSw.ToString(); jsonSw.Close(); ctx.Reports.Add(new UploadedReport(reportV2)); ctx.SaveChanges(); MemoryStream pgpIn = new MemoryStream(Encoding.UTF8.GetBytes(reportV2String)); MemoryStream pgpOut = new MemoryStream(); ChoPGPEncryptDecrypt pgp = new ChoPGPEncryptDecrypt(); pgp.Encrypt(pgpIn, pgpOut, Path.Combine(HostingEnvironment.MapPath("~") ?? throw new InvalidOperationException(), "public.asc"), true); pgpOut.Position = 0; reportV2String = Encoding.UTF8.GetString(pgpOut.ToArray()); MimeMessage message = new MimeMessage { Subject = "New device report (old version)", Body = new TextPart("plain") { Text = reportV2String } }; message.From.Add(new MailboxAddress("DiscImageChef", "*****@*****.**")); message.To.Add(new MailboxAddress("Natalia Portillo", "*****@*****.**")); using (SmtpClient client = new SmtpClient()) { client.Connect("mail.claunia.com", 25, false); client.Send(message); client.Disconnect(true); } response.Content = new StringContent("ok", Encoding.UTF8, "text/plain"); return(response); } // ReSharper disable once RedundantCatchClause catch { #if DEBUG if (Debugger.IsAttached) { throw; } #endif response.Content = new StringContent("error", Encoding.UTF8, "text/plain"); return(response); } }
public HttpResponseMessage UploadReportV2() { HttpResponseMessage response = new HttpResponseMessage { StatusCode = HttpStatusCode.OK }; try { HttpRequest request = HttpContext.Current.Request; StreamReader sr = new StreamReader(request.InputStream); string reportJson = sr.ReadToEnd(); DeviceReportV2 newReport = JsonConvert.DeserializeObject <DeviceReportV2>(reportJson); if (newReport == null) { response.Content = new StringContent("notstats", Encoding.UTF8, "text/plain"); return(response); } ctx.Reports.Add(new UploadedReport(newReport)); ctx.SaveChanges(); MemoryStream pgpIn = new MemoryStream(Encoding.UTF8.GetBytes(reportJson)); MemoryStream pgpOut = new MemoryStream(); ChoPGPEncryptDecrypt pgp = new ChoPGPEncryptDecrypt(); pgp.Encrypt(pgpIn, pgpOut, Path.Combine(HostingEnvironment.MapPath("~") ?? throw new InvalidOperationException(), "public.asc"), true); pgpOut.Position = 0; reportJson = Encoding.UTF8.GetString(pgpOut.ToArray()); MimeMessage message = new MimeMessage { Subject = "New device report", Body = new TextPart("plain") { Text = reportJson } }; message.From.Add(new MailboxAddress("DiscImageChef", "*****@*****.**")); message.To.Add(new MailboxAddress("Natalia Portillo", "*****@*****.**")); using (SmtpClient client = new SmtpClient()) { client.Connect("mail.claunia.com", 25, false); client.Send(message); client.Disconnect(true); } response.Content = new StringContent("ok", Encoding.UTF8, "text/plain"); return(response); } // ReSharper disable once RedundantCatchClause catch { #if DEBUG if (Debugger.IsAttached) { throw; } #endif response.Content = new StringContent("error", Encoding.UTF8, "text/plain"); return(response); } }