Advertisement
Guest User

Untitled

a guest
Dec 10th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.18 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Security.Cryptography;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Windows.Forms;
  12. namespace Criptare
  13. {
  14. public partial class Form1 : Form
  15. {
  16.  
  17. AesCryptoServiceProvider cryptoProvider;
  18. ICryptoTransform encryptor;
  19. ICryptoTransform decryptor;
  20. public Form1()
  21. {
  22. InitializeComponent();
  23. cryptoProvider= new AesCryptoServiceProvider();
  24. encryptor = cryptoProvider.CreateEncryptor();
  25.  
  26. }
  27.  
  28. private void button1_Click(object sender, EventArgs e) {
  29. var fileContent = string.Empty;
  30. var filePath = string.Empty;
  31. using (OpenFileDialog openFileDialog = new OpenFileDialog())
  32. {
  33. if (openFileDialog.ShowDialog() == DialogResult.OK)
  34. {
  35. filePath = openFileDialog.FileName;
  36. var fileStream = openFileDialog.OpenFile();
  37. }
  38. }
  39. MessageBox.Show(fileContent, "File Content at path: " + filePath, MessageBoxButtons.OK);
  40. FileStream fin = new FileStream(filePath, FileMode.Open, FileAccess.Read);
  41. FileStream fout = new FileStream("D:/dest.enc", FileMode.OpenOrCreate, FileAccess.Write);
  42.  
  43. CryptoStream stream = new CryptoStream(fout, encryptor, CryptoStreamMode.Write);
  44. byte[] input = new byte[128];
  45. int inLen = -1;
  46. while ((inLen = fin.Read(input, 0, 128)) > 0)
  47. {
  48. stream.Write(input, 0, inLen);
  49. }
  50. stream.Close(); fout.Close(); fin.Close();
  51. }
  52.  
  53. private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
  54. {
  55.  
  56. }
  57.  
  58. private void button2_Click(object sender, EventArgs e)
  59. {
  60. var fileContent = string.Empty;
  61. var filePath = string.Empty;
  62. using (OpenFileDialog openFileDialog = new OpenFileDialog())
  63. {
  64. if (openFileDialog.ShowDialog() == DialogResult.OK)
  65. {
  66. filePath = openFileDialog.FileName;
  67. var fileStream = openFileDialog.OpenFile();
  68. }
  69. }
  70. MessageBox.Show(fileContent, "File Content at path: " + filePath, MessageBoxButtons.OK);
  71. FileStream fin = new FileStream("D://dest.enc", FileMode.Open, FileAccess.Read);
  72. FileStream fout = new FileStream("D://source.enc.dec.jpg", FileMode.OpenOrCreate, FileAccess.Write);
  73. decryptor = cryptoProvider.CreateDecryptor(cryptoProvider.Key,cryptoProvider.IV);
  74. CryptoStream stream = new CryptoStream(fout,decryptor, CryptoStreamMode.Write);
  75. byte[] input = new byte[128];
  76. int inLen = -1;
  77. while ((inLen = fin.Read(input, 0, 128)) > 0)
  78. {
  79. stream.Write(input, 0, inLen);
  80. }
  81. stream.Close(); fout.Close(); fin.Close();
  82.  
  83. }
  84. }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement