private static void GenerateKeyPair() { using (ChoPGPEncryptDecrypt pgp = new ChoPGPEncryptDecrypt()) pgp.GenerateKey("pub.asc", "pri.asc", "*****@*****.**", "Test123"); Console.WriteLine("PGP KeyPair generated."); }
public void DecryptFile() { using (ChoPGPEncryptDecrypt pgp = new ChoPGPEncryptDecrypt()) { pgp.DecryptFile("SampleData.PGP", "SampleData.OUT", "Sample_Pri.asc", "Test123"); Console.WriteLine("PGP Decryption done."); } }
public void EncryptFileNSign() { using (ChoPGPEncryptDecrypt pgp = new ChoPGPEncryptDecrypt()) { pgp.EncryptFileAndSign("SampleData.txt", "SampleData.PGP", "Sample_Pub.asc", "Sample_Pri.asc", "Test123", true, false); Console.WriteLine("PGP Encryption done."); } }
private static void EncryptFile() { using (ChoPGPEncryptDecrypt pgp = new ChoPGPEncryptDecrypt()) { pgp.EncryptFile("SampleData.txt", "SampleData.PGP", "Sample_Pub.asc", true, false); Console.WriteLine("PGP Encryption done."); } }
private static void DecryptFileNVerify() { using (ChoPGPEncryptDecrypt pgp = new ChoPGPEncryptDecrypt()) { pgp.DecryptFileAndVerify("SampleData.PGP", "SampleData.OUT", "Sample_Pub.asc", "Sample_Pri.asc", "Test123"); Console.WriteLine("PGP Decryption done."); } }
private static void DecryptFile() { using (ChoPGPEncryptDecrypt pgp = new ChoPGPEncryptDecrypt()) { //pgp.CompressionAlgorithm = ChoCompressionAlgorithm.Zip; pgp.DecryptFile("SampleData.PGP", "SampleData.OUT", "Pri.asc", "Test123"); Console.WriteLine("PGP Decryption done."); } }
private static void EncryptFileNSign() { using (ChoPGPEncryptDecrypt pgp = new ChoPGPEncryptDecrypt()) { //pgp.CompressionAlgorithm = ChoCompressionAlgorithm.Zip; pgp.EncryptFileAndSign("SampleData.txt", "SampleData.PGP", "Sample_Pub.asc", "Sample_Pri.asc", "Test123", true, false); Console.WriteLine("PGP Encryption done."); } }
public async Task <bool> UploadFileAndEncryptAsync(FileCrypt fileCrypt, Stream stream) { fileCrypt.FileCryptId = await this._fileCryptRepository.SaveFileDetailsForEncryptionAsync(fileCrypt); Assembly asm = Assembly.GetExecutingAssembly(); var memoryStream = new MemoryStream(); var memoryStreamEncrypted = new MemoryStream(); string tempFilePath = ""; fileCrypt.EncryptedFileName = "FileEncrypt_" + fileCrypt.FileCryptId.ToString(); fileCrypt.EncryptedFileFullPath = fileCrypt.EncryptedFilePath + fileCrypt.EncryptedFileName + fileCrypt.EncryptedFileExtension; tempFilePath = fileCrypt.EncryptedFilePath + fileCrypt.EncryptedFileName + ".temp"; string path = System.IO.Path.GetDirectoryName(asm.Location); string privateKeyFileFullPath = path + @"\" + GlobalAppConfigurations.Instance.GetValue("PGPPrivateKeyFileFullPath").ToString(); string publicKeyFileFullPath = path + @"\" + GlobalAppConfigurations.Instance.GetValue("PGPPublicKeyFileFullPath").ToString(); string pgpKeyPassword = GlobalAppConfigurations.Instance.GetValue("PGPKeyPassword").ToString(); // Write File from stream to Byte await stream.CopyToAsync(memoryStream); byte[] fileInByte = memoryStream.ToArray(); // Save Encrytped File byte to File using (var fileStream = new FileStream(tempFilePath, FileMode.OpenOrCreate, FileAccess.ReadWrite)) using (var memoryStreamToFile = new MemoryStream(fileInByte)) { byte[] bytes = new byte[memoryStreamToFile.Length]; await memoryStreamToFile.ReadAsync(bytes, 0, (int)memoryStreamToFile.Length); await fileStream.WriteAsync(bytes, 0, bytes.Length); } using (ChoPGPEncryptDecrypt pgp = new ChoPGPEncryptDecrypt()) { try { await pgp.EncryptFileAsync(tempFilePath, fileCrypt.EncryptedFileFullPath, publicKeyFileFullPath, true, true); } catch (Exception ex) { throw ex; } } if (File.Exists(tempFilePath)) { File.Delete(tempFilePath); } bool isUpdateSuccess = await this._fileCryptRepository.UpdateFileDetailsAfterEncryptionAsync(fileCrypt); return(isUpdateSuccess); }
public ChoPGPEncryptDecrypt NewPGPEncryptDecrypt() { ChoPGPEncryptDecrypt pgp = new ChoPGPEncryptDecrypt(); pgp.CompressionAlgorithm = CompressionAlgorithm; pgp.SymmetricKeyAlgorithm = SymmetricKeyAlgorithm; pgp.PublicKeyAlgorithm = PublicKeyAlgorithm; pgp.PgpSignatureType = (int)PgpSignature; return(pgp); }
private MemoryStream EncryptNSignInMemory(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.EncryptAndSign(stream, a, "Sample_Pub.asc", "Sample_Pri.asc", "Test123", true, false); return(a); } }
private string DecryptString(MemoryStream text, string pass) { using (ChoPGPEncryptDecrypt pgp = new ChoPGPEncryptDecrypt()) { using (MemoryStream a = new System.IO.MemoryStream()) { byte[] r = pgp.DecryptInMemory(text.ToArray(), File.OpenRead("Sample_Pri.asc"), pass); MemoryStream ms = new MemoryStream(r); StreamReader reader = new StreamReader(ms); return(reader.ReadToEnd()); } } }
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); } } } }
public void EncryptNSign() { using (ChoPGPEncryptDecrypt pgp = new ChoPGPEncryptDecrypt()) { using (Stream input = File.OpenRead("SampleData.txt")) { using (Stream output = File.OpenWrite("SampleData.PGP")) { pgp.EncryptAndSign(input, output, "Sample_Pub.asc", "Sample_Pri.asc", "Test123", true, false); } } } Console.WriteLine("PGP Encryption done."); }
private static void Decrypt() { using (ChoPGPEncryptDecrypt pgp = new ChoPGPEncryptDecrypt()) { using (Stream input = File.OpenRead("SampleData.PGP")) { using (Stream output = File.OpenWrite("SampleData.OUT")) { pgp.Decrypt(input, output, "Sample_Pri.asc", "Test123"); } } Console.WriteLine("PGP Decryption done."); } }
private async void btnDecrypt_Click(object sender, RoutedEventArgs e) { try { ChoPGPEncryptDecrypt pgp = PGPOptions.NewPGPEncryptDecrypt(); await pgp.DecryptFileAsync(PGPDecryptFileOptions.InputFilePath, PGPDecryptFileOptions.OutputFilePath, PGPDecryptFileOptions.PrivateKeyFilePath, PGPDecryptFileOptions.PassPhrase); MessageBox.Show("PGP decryption successful.", Title, MessageBoxButton.OK, MessageBoxImage.Information); } catch (Exception ex) { MessageBox.Show("Error occurred during PGP decryption. " + ex.Message, Title, MessageBoxButton.OK, MessageBoxImage.Error); } }
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); } } } }
private static void EncryptNSign() { using (ChoPGPEncryptDecrypt pgp = new ChoPGPEncryptDecrypt()) { using (Stream input = File.OpenRead("SampleData.txt")) { using (Stream output = File.OpenWrite("SampleData.PGP")) { //pgp.CompressionAlgorithm = ChoCompressionAlgorithm.Zip; pgp.EncryptAndSign(input, output, "Sample_Pub.asc", "Sample_Pri.asc", "Test123", true, false); } } } Console.WriteLine("PGP Encryption done."); }
private async void btnGenerateKey_Click(object sender, RoutedEventArgs e) { try { ChoPGPEncryptDecrypt pgp = PGPOptions.NewPGPEncryptDecrypt(); await pgp.GenerateKeyAsync(PGPGenerateKeyOptions.PublicKeyFilePath, PGPGenerateKeyOptions.PrivateKeyFilePath, PGPGenerateKeyOptions.Identity, PGPGenerateKeyOptions.PassPhrase, PGPGenerateKeyOptions.Strength, PGPGenerateKeyOptions.Certainty); MessageBox.Show("PGP key generation successful.", Title, MessageBoxButton.OK, MessageBoxImage.Information); } catch (Exception ex) { MessageBox.Show("Error occurred during PGP key generation. " + ex.Message, Title, MessageBoxButton.OK, MessageBoxImage.Error); } }
public static void initialize(TestContext testContext) { if (!File.Exists("SampleData.txt")) { File.Create("SampleData.txt").Close(); } using (FileStream fs = File.OpenWrite("SampleData.txt")) { string data = "hola"; byte[] information = new UTF8Encoding(true).GetBytes(data); fs.Write(information, 0, information.Length); } using (ChoPGPEncryptDecrypt pgp = new ChoPGPEncryptDecrypt()) pgp.GenerateKey("Sample_Pub.asc", "Sample_Pri.asc", "*****@*****.**", "Test123"); Console.WriteLine("PGP KeyPair generated."); }
private string DecryptNVerifyInMemory(MemoryStream text, string pass) { using (ChoPGPEncryptDecrypt pgp = new ChoPGPEncryptDecrypt()) { using (MemoryStream a = new System.IO.MemoryStream()) { Stream message; message = pgp.DecryptAndVerifyInMemory(text, a, "Sample_Pub.asc", "Sample_Pri.asc", pass); MemoryStream ms = new MemoryStream();; message.CopyTo(ms); ms = new MemoryStream(a.ToArray()); StreamReader reader = new StreamReader(ms); return(reader.ReadToEnd()); } } }
static void encrypt_file(string localpath, string filename) { Console.WriteLine("Encrypting file " + filename); try { using (ChoPGPEncryptDecrypt pgp = new ChoPGPEncryptDecrypt()) { pgp.EncryptFile(localpath, @"c:\ftp_down\" + filename + ".PGP", @"c:\ftp_down\pkey.asc", true, false); } Console.WriteLine("File encrypted and available....."); File.Delete(@"c:\ftp_down\" + filename); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
public static async Task <string> EncryptRSATextToTextAsync(string text, string publicKey) { byte[] byteArrayText = Encoding.UTF8.GetBytes(text); MemoryStream encMemoryStream1 = new MemoryStream(byteArrayText); byte[] byteArrayPubKey = Encoding.UTF8.GetBytes(publicKey); MemoryStream streamPub = new MemoryStream(byteArrayPubKey); var streamEncOut = new MemoryStream(); using (ChoPGPEncryptDecrypt pgp = new ChoPGPEncryptDecrypt()) { await pgp.EncryptAsync(encMemoryStream1, streamEncOut, streamPub); } byte[] encryptedBytes = streamEncOut.ToArray(); var encryptedText = Encoding.UTF8.GetString(encryptedBytes); return(encryptedText); }
public static async Task <string> DecryptRSATextToTextAsync(string text, string privateKey, string passphrase) { byte[] byteArrayText1 = Encoding.UTF8.GetBytes(text); MemoryStream encMemoryStream1 = new MemoryStream(byteArrayText1); byte[] byteArrayPrvKey = Encoding.UTF8.GetBytes(privateKey); MemoryStream streamPrv = new MemoryStream(byteArrayPrvKey); var streamDecOut = new MemoryStream(); using (ChoPGPEncryptDecrypt pgp = new ChoPGPEncryptDecrypt()) { await pgp.DecryptAsync(encMemoryStream1, streamDecOut, streamPrv, passphrase); } byte[] decryptedBytes = streamDecOut.ToArray(); var decryptedText = Encoding.UTF8.GetString(decryptedBytes); return(decryptedText); }
public async Task <(FileCrypt fileDetails, MemoryStream memoryStream)> DecryptAndDownloadFileAsync(long fileCryptId) { MemoryStream memoryStream = new MemoryStream(); MemoryStream decryptMemoryStream = new MemoryStream(); Assembly asm = Assembly.GetExecutingAssembly(); string path = System.IO.Path.GetDirectoryName(asm.Location); string privateKeyFileFullPath = path + @"\" + GlobalAppConfigurations.Instance.GetValue("PGPPrivateKeyFileFullPath").ToString(); string publicKeyFileFullPath = path + @"\" + GlobalAppConfigurations.Instance.GetValue("PGPPublicKeyFileFullPath").ToString(); string pgpKeyPassword = GlobalAppConfigurations.Instance.GetValue("PGPKeyPassword").ToString(); FileCrypt fileCrypt = await this._fileCryptRepository.GetEncryptedFileDetailsAsync(fileCryptId); await this._fileCryptRepository.SaveFileDecryptionHistoryAsync(fileCrypt); using (var stream = new FileStream(fileCrypt.EncryptedFileFullPath, FileMode.Open)) { await stream.CopyToAsync(memoryStream); } memoryStream.Position = 0; using (ChoPGPEncryptDecrypt pgp = new ChoPGPEncryptDecrypt()) { try { pgp.Decrypt(memoryStream, decryptMemoryStream, privateKeyFileFullPath, pgpKeyPassword); } catch (Exception ex) { throw ex; } } decryptMemoryStream.Position = 0; return(fileCrypt, decryptMemoryStream); }
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(); await jsonSw.WriteAsync(JsonConvert.SerializeObject(reportV2, Formatting.Indented, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore })); string reportV2String = jsonSw.ToString(); jsonSw.Close(); var newUploadedReport = new UploadedReport(reportV2); // Ensure CHS and CurrentCHS are not duplicates if (newUploadedReport.ATA?.ReadCapabilities?.CHS != null && newUploadedReport.ATA?.ReadCapabilities?.CurrentCHS != null) { if (newUploadedReport.ATA.ReadCapabilities.CHS.Cylinders == newUploadedReport.ATA.ReadCapabilities.CurrentCHS.Cylinders && newUploadedReport.ATA.ReadCapabilities.CHS.Heads == newUploadedReport.ATA.ReadCapabilities.CurrentCHS.Heads && newUploadedReport.ATA.ReadCapabilities.CHS.Sectors == newUploadedReport.ATA.ReadCapabilities.CurrentCHS.Sectors) { newUploadedReport.ATA.ReadCapabilities.CHS = newUploadedReport.ATA.ReadCapabilities.CurrentCHS; } } // Check if the CHS or CurrentCHS of this report already exist in the database if (newUploadedReport.ATA?.ReadCapabilities?.CHS != null) { Chs existingChs = _ctx.Chs.FirstOrDefault(c => c.Cylinders == newUploadedReport.ATA.ReadCapabilities.CHS.Cylinders && c.Heads == newUploadedReport.ATA.ReadCapabilities.CHS.Heads && c.Sectors == newUploadedReport.ATA.ReadCapabilities.CHS.Sectors); if (existingChs != null) { newUploadedReport.ATA.ReadCapabilities.CHS = existingChs; } } if (newUploadedReport.ATA?.ReadCapabilities?.CurrentCHS != null) { Chs existingChs = _ctx.Chs.FirstOrDefault(c => c.Cylinders == newUploadedReport.ATA.ReadCapabilities.CurrentCHS. Cylinders && c.Heads == newUploadedReport.ATA.ReadCapabilities.CurrentCHS.Heads && c.Sectors == newUploadedReport.ATA.ReadCapabilities.CurrentCHS.Sectors); if (existingChs != null) { newUploadedReport.ATA.ReadCapabilities.CurrentCHS = existingChs; } } if (newUploadedReport.ATA?.RemovableMedias != null) { foreach (TestedMedia media in newUploadedReport.ATA.RemovableMedias) { if (media.CHS != null && media.CurrentCHS != null) { if (media.CHS.Cylinders == media.CurrentCHS.Cylinders && media.CHS.Heads == media.CurrentCHS.Heads && media.CHS.Sectors == media.CurrentCHS.Sectors) { media.CHS = media.CurrentCHS; } } if (media.CHS != null) { Chs existingChs = _ctx.Chs.FirstOrDefault(c => c.Cylinders == media.CHS.Cylinders && c.Heads == media.CHS.Heads && c.Sectors == media.CHS.Sectors); if (existingChs != null) { media.CHS = existingChs; } } if (media.CHS != null) { Chs existingChs = _ctx.Chs.FirstOrDefault(c => c.Cylinders == media.CurrentCHS.Cylinders && c.Heads == media.CurrentCHS.Heads && c.Sectors == media.CurrentCHS.Sectors); if (existingChs != null) { media.CurrentCHS = existingChs; } } } } await _ctx.Reports.AddAsync(newUploadedReport); await _ctx.SaveChangesAsync(); var pgpIn = new MemoryStream(Encoding.UTF8.GetBytes(reportV2String)); var pgpOut = new MemoryStream(); var pgp = new ChoPGPEncryptDecrypt(); await pgp.EncryptAsync(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("Aaru Server", "*****@*****.**")); message.To.Add(new MailboxAddress("Natalia Portillo", "*****@*****.**")); using (var client = new SmtpClient()) { await client.ConnectAsync("mail.claunia.com", 25, false); await client.SendAsync(message); await client.DisconnectAsync(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> 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 void TESTGenerateKeyPair() { using (ChoPGPEncryptDecrypt pgp = new ChoPGPEncryptDecrypt()) pgp.GenerateKey("Sample_Pub.asc", "Sample_Pri.asc", "*****@*****.**", "Test123"); Console.WriteLine("PGP KeyPair generated."); }
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); } }