Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.IO;
- using System.Linq;
- using System.Security.Cryptography;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace Criptare
- {
- public partial class Form1 : Form
- {
- AesCryptoServiceProvider cryptoProvider;
- ICryptoTransform encryptor;
- ICryptoTransform decryptor;
- public Form1()
- {
- InitializeComponent();
- cryptoProvider= new AesCryptoServiceProvider();
- encryptor = cryptoProvider.CreateEncryptor();
- }
- private void button1_Click(object sender, EventArgs e) {
- var fileContent = string.Empty;
- var filePath = string.Empty;
- using (OpenFileDialog openFileDialog = new OpenFileDialog())
- {
- if (openFileDialog.ShowDialog() == DialogResult.OK)
- {
- filePath = openFileDialog.FileName;
- var fileStream = openFileDialog.OpenFile();
- }
- }
- MessageBox.Show(fileContent, "File Content at path: " + filePath, MessageBoxButtons.OK);
- FileStream fin = new FileStream(filePath, FileMode.Open, FileAccess.Read);
- FileStream fout = new FileStream("D:/dest.enc", FileMode.OpenOrCreate, FileAccess.Write);
- CryptoStream stream = new CryptoStream(fout, encryptor, CryptoStreamMode.Write);
- byte[] input = new byte[128];
- int inLen = -1;
- while ((inLen = fin.Read(input, 0, 128)) > 0)
- {
- stream.Write(input, 0, inLen);
- }
- stream.Close(); fout.Close(); fin.Close();
- }
- private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
- {
- }
- private void button2_Click(object sender, EventArgs e)
- {
- var fileContent = string.Empty;
- var filePath = string.Empty;
- using (OpenFileDialog openFileDialog = new OpenFileDialog())
- {
- if (openFileDialog.ShowDialog() == DialogResult.OK)
- {
- filePath = openFileDialog.FileName;
- var fileStream = openFileDialog.OpenFile();
- }
- }
- MessageBox.Show(fileContent, "File Content at path: " + filePath, MessageBoxButtons.OK);
- FileStream fin = new FileStream("D://dest.enc", FileMode.Open, FileAccess.Read);
- FileStream fout = new FileStream("D://source.enc.dec.jpg", FileMode.OpenOrCreate, FileAccess.Write);
- decryptor = cryptoProvider.CreateDecryptor(cryptoProvider.Key,cryptoProvider.IV);
- CryptoStream stream = new CryptoStream(fout,decryptor, CryptoStreamMode.Write);
- byte[] input = new byte[128];
- int inLen = -1;
- while ((inLen = fin.Read(input, 0, 128)) > 0)
- {
- stream.Write(input, 0, inLen);
- }
- stream.Close(); fout.Close(); fin.Close();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement