Частина тексту файла (без зображень, графіків і формул):
Міністерство освіти і науки України
Національний університет „Львівська політехніка”
Кафедра ЕОМ
Звіт
з лабораторної роботи №8
з дисципліни:”Захист інформації в комп’ютерних системах ”
на тему:”Шифрування даних за допомогою AES”
/
/
/
/
/
/
/
/
/
Хід роботи
/
Рис.1 Графічний інтерфейс програми
/
Рис.2 Вхідні дані
/
Рис.3 Закодовані дані
/
Рис.4 Декодовані дані
Висновок:Під час виконання лабораторної роботи було розроблену програму,яка виконує кодування та декодуваня інформації по Алгоритму AES,яка нагляно представляє його роботу.
Код програми
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using System.Security.Cryptography;
namespace SimpleEncrypt
{
public partial class Form1 : Form
{
private byte[] IV = System.Text.Encoding.UTF8.GetBytes("khortashkooleksa");
private int BlockSize = 128;
public Form1()
{
InitializeComponent();
}
private void Browse_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() == DialogResult.Cancel) return;
textBoxFilename.Text = openFileDialog1.FileName;
FileStream fs = new FileStream(openFileDialog1.FileName, FileMode.Open);
StreamReader sr = new StreamReader(fs);
richTextBox1.Text = sr.ReadToEnd();
sr.Close();
fs.Close();
}
private void Save_Click(object sender, EventArgs e)
{
if (saveFileDialog1.ShowDialog() == DialogResult.Cancel) return;
FileStream fs = new FileStream(saveFileDialog1.FileName, FileMode.OpenOrCreate);
StreamWriter sw = new StreamWriter(fs);
sw.Write(richTextBox1.Text);
sw.Close();
fs.Close();
}
private void Encrypt_Click(object sender, EventArgs e)
{
if (textBoxPassword.Text == "") return;
byte[] bytes = Encoding.Unicode.GetBytes(richTextBox1.Text);
//Encrypt
SymmetricAlgorithm crypt = Aes.Create();
HashAlgorithm hash = MD5.Create();
crypt.BlockSize = BlockSize;
crypt.Key = hash.ComputeHash(Encoding.Unicode.GetBytes(textBoxPassword.Text));
crypt.IV = IV;
crypt.Mode = CipherMode.CFB;
using (MemoryStream memoryStream = new MemoryStream())
{
using (CryptoStream cryptoStream = new CryptoStream(memoryStream, crypt.CreateEncryptor(), CryptoStreamMode.Write))
{
cryptoStream.Write(bytes, 0, bytes.Length);
}
richTextBox1.Text = Convert.ToBase64String(memoryStream.ToArray());
}
}
private void Decrypt_Click(object sender, EventArgs e)
{
if (textBoxPassword.Text == "") return;
//Decrypt
byte[] bytes = Convert.FromBase64String(richTextBox1.Text);
SymmetricAlgorithm crypt = Aes.Create();
HashAlgorithm hash = MD5.Create();
crypt.Key = hash.ComputeHash(Encoding.Unicode.GetBytes(textBoxPassword.Text));
crypt.IV = IV;
crypt.Mode = CipherMode.CFB;
using (MemoryStream memoryStream = new MemoryStream(bytes))
{
using (CryptoStream cryptoStream = new CryptoStream(memoryStream, crypt.CreateDecryptor(), CryptoStreamMode.Read))
{
byte[] decryptedBytes = new byte[bytes.Length];
cryptoStream.Read(decryptedBytes, 0, decryptedBytes.Length);
richTextBox1.Text = Encoding.Unicode.GetString(decryptedBytes);
}
}
}
private void Delete_Click(object sender, EventArgs e)
{
try
{
if (textBoxFilename.Text == "") return;
File.Delete(textBoxFilename.Text);
MessageBox.Show("File deleted:\n" + textBoxFilename.Text);
}
catch(Exception ex)
{
MessageBox.Show("Unable to delete file!\n" + ex.Message);
}
}
}
}