Мета:
Ознайомитися з алгоритмом CAST 128.
Теоретичний вступ
У криптографії, CAST-128 (або CAST5) блоковий алгоритм симетричного шифрування на основі мережі Фейстеля, який використовується в цілому ряду продуктів криптографічного захисту, зокрема деяких версіях PGP і GPG і крім того схвалений для використання Канадським урядом. Алгоритм був створений в 1996 році Карлайлом Адамсом (Carlisle Adams) і Стаффордом Таваресом (Stafford Tavares) використовуючи метод побудови шифрів CAST, який використовується також і іншим їх алгоритмом CAST-256 (алгоритм-кандидат AES). CAST-128 складається з 12 або 16 раундів мережі Фейстеля з розміром блоку 64 біта і довжиною ключа від 40 до 128 біт (але лише з инкрементацией по 8 біт). 16 раундів використовуються коли розміри ключа перевищують 80 біт. У алгоритмі використовуються 8x16 S- блоки, засновані на bent-функциях, операції XOR і модулярной арифметиці (модулярное складання і віднімання). Є три різні типи функцій раундів, але вони схожі по структурі і розрізняються лише у виборі виконуваної операції (складання, віднімання або XOR) в різних місцях. Хоча CAST-128 захищений патентом Entrust, його можна використовувати у всьому світі для комерційних або некомерційних цілей безкоштовно.
Текст програми
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Runtime.InteropServices;
using System.IO;
using System.Text;
using System.Security.Cryptography;
using AcedUtils;
namespace Sample
{
public class MainForm : System.Windows.Forms.Form
{
private const string
DemoRegistryKey = "Software\\AcedUtils.NET\\Demo",
cfgStreamFileName = "StreamFileName",
cfgCompressionLevel = "CompressionLevel";
private static uint _tickCount;
private static int _streamLength;
private static string _streamFileName = String.Empty;
private static AcedCompressionLevel _compressionLevel;
private AcedMemoryWriter _writer;
private AcedMemoryReader _reader;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.ColumnHeader columnHeader1;
private System.Windows.Forms.ColumnHeader columnHeader2;
private System.Windows.Forms.ColumnHeader columnHeader3;
private System.Windows.Forms.GroupBox groupBox2;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.ColumnHeader columnHeader4;
private System.Windows.Forms.ColumnHeader columnHeader5;
private System.Windows.Forms.ColumnHeader columnHeader6;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Button saveStreamButton;
private System.Windows.Forms.Button closeButton;
private System.Windows.Forms.Button saveFileButton;
private System.Windows.Forms.Label outputLengthLabel;
private System.Windows.Forms.ListView outputList;
private System.Windows.Forms.Label inputLengthLabel;
private System.Windows.Forms.ListView inputList;
private System.Windows.Forms.Button openFileButton;
private System.Windows.Forms.Button openStreamButton;
private System.Windows.Forms.OpenFileDialog openFileDialog;
private System.Windows.Forms.SaveFileDialog saveStreamDialog;
private System.Windows.Forms.OpenFileDialog openStreamDialog;
private System.Windows.Forms.SaveFileDialog saveFileDialog;
private System.Windows.Forms.Button clearOutputStreamButton;
private System.Windows.Forms.CheckBox encryptCheck;
private System.Windows.Forms.CheckBox decryptCheck;
private System.Windows.Forms.CheckBox garbleDataCheck;
private System.Windows.Forms.TextBox encryptPasswordEdit;
private System.Windows.Forms.TextBox decryptPasswordEdit;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label storedSizeLabel;
private System.Windows.Forms.ComboBox compressionLevelCombo;
private System.Windows.Forms.Label label3;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public MainForm()
{
InitializeComponent();
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.label3 = new System.Windows.Forms.Label();
this.compressionLevelCombo = new System.Windows.Forms.ComboBox();
this.outputLengthLabel = new System.Windows.Forms.Label();
this.garbleDataCheck = new System.Windows.Forms.CheckBox();
this.encryptPasswordEdit = new System.Windows.Forms.TextBox();
this.encryptCheck = new System.Windows.Forms.CheckBox();
this.label1 = new System.Windows.Forms.Label();
this.saveStreamButton = new System.Windows.Forms.Button();
this.clearOutputStreamButton = new System.Windows.Forms.Button();
this.openFileButton = new System.Windows.Forms.Button();
this.outputList = new System.Windows.Forms.ListView();
this.columnHeader1 = new System.Windows.Forms.ColumnHeader();
this.columnHeader2 = new System.Windows.Forms.ColumnHeader();
this.columnHeader3 = new System.Windows.Forms.ColumnHeader();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.storedSizeLabel = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.inputLengthLabel = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.closeButton = new System.Windows.Forms.Button();
this.saveFileButton = new System.Windows.Forms.Button();
this.openStreamButton = new System.Windows.Forms.Button();
this.decryptPasswordEdit = new System.Windows.Forms.TextBox();
this.decryptCheck = new System.Windows.Forms.CheckBox();
this.inputList = new System.Windows.Forms.ListView();
this.columnHeader4 = new System.Windows.Forms.ColumnHeader();
this.columnHeader5 = new System.Windows.Forms.ColumnHeader();
this.columnHeader6 = new System.Windows.Forms.ColumnHeader();
this.openFileDialog = new System.Windows.Forms.OpenFileDialog();
this.saveStreamDialog = new System.Windows.Forms.SaveFileDialog();
this.openStreamDialog = new System.Windows.Forms.OpenFileDialog();
this.saveFileDialog = new System.Windows.Forms.SaveFileDialog();
this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout();
this.SuspendLayout();
//
// groupBox1
//
this.groupBox1.Controls.Add(this.label3);
this.groupBox1.Controls.Add(this.compressionLevelCombo);
this.groupBox1.Controls.Add(this.outputLengthLabel);
this.groupBox1.Controls.Add(this.garbleDataCheck);
this.groupBox1.Controls.Add(this.encryptPasswordEdit);
this.groupBox1.Controls.Add(this.encryptCheck);
this.groupBox1.Controls.Add(this.label1);
this.groupBox1.Controls.Add(this.saveStreamButton);
this.groupBox1.Controls.Add(this.clearOutputStreamButton);
this.groupBox1.Controls.Add(this.openFileButton);
this.groupBox1.Controls.Add(this.outputList);
this.groupBox1.Location = new System.Drawing.Point(8, 8);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(584, 208);
this.groupBox1.TabIndex = 0;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Запис у двійковий потік";
//
// label3
//
this.label3.Location = new System.Drawing.Point(12, 181);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(48, 16);
this.label3.TabIndex = 6;
this.label3.Text = "Сжатие:";
this.label3.Visible = false;
//
// compressionLevelCombo
//
this.compressionLevelCombo.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.compressionLevelCombo.Items.AddRange(new object[] {
"Без сжатия",
"Сверхбыстрое",
"Быстрое",
"Нормальное",
"Максимальное"});
this.compressionLevelCombo.Location = new System.Drawing.Point(64, 178);
this.compressionLevelCombo.Name = "compressionLevelCombo";
this.compressionLevelCombo.Size = new System.Drawing.Size(100, 21);
this.compressionLevelCombo.TabIndex = 7;
this.compressionLevelCombo.Visible = false;
//
// outputLengthLabel
//
this.outputLengthLabel.Location = new System.Drawing.Point(428, 116);
this.outputLengthLabel.Name = "outputLengthLabel";
this.outputLengthLabel.Size = new System.Drawing.Size(148, 16);
this.outputLengthLabel.TabIndex = 4;
this.outputLengthLabel.Text = "(інформації немає)";
this.outputLengthLabel.TextAlign = System.Drawing.ContentAlignment.TopCenter;
//
// garbleDataCheck
//
this.garbleDataCheck.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.garbleDataCheck.Location = new System.Drawing.Point(416, 178);
this.garbleDataCheck.Name = "garbleDataCheck";
this.garbleDataCheck.Size = new System.Drawing.Size(166, 21);
this.garbleDataCheck.TabIndex = 10;
this.garbleDataCheck.Text = "Инвертировать третий байт";
this.garbleDataCheck.Visible = false;
//
// encryptPasswordEdit
//
this.encryptPasswordEdit.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.encryptPasswordEdit.Location = new System.Drawing.Point(170, 178);
this.encryptPasswordEdit.Name = "encryptPasswordEdit";
this.encryptPasswordEdit.Size = new System.Drawing.Size(240, 21);
this.encryptPasswordEdit.TabIndex = 9;
//
// encryptCheck
//
this.encryptCheck.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.encryptCheck.Location = new System.Drawing.Point(15, 181);
this.encryptCheck.Name = "encryptCheck";
this.encryptCheck.Size = new System.Drawing.Size(144, 21);
this.encryptCheck.TabIndex = 8;
this.encryptCheck.Text = "Шифрувати з паролем:";
//
// label1
//
this.label1.Location = new System.Drawing.Point(448, 88);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(112, 28);
this.label1.TabIndex = 3;
this.label1.Text = "Загальний розмір в потоці:";
this.label1.TextAlign = System.Drawing.ContentAlignment.TopCenter;
//
// saveStreamButton
//
this.saveStreamButton.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.saveStreamButton.Location = new System.Drawing.Point(436, 145);
this.saveStreamButton.Name = "saveStreamButton";
this.saveStreamButton.Size = new System.Drawing.Size(132, 23);
this.saveStreamButton.TabIndex = 5;
this.saveStreamButton.Text = "Записати на диск...";
this.saveStreamButton.Click += new System.EventHandler(this.saveStreamButton_Click);
//
// clearOutputStreamButton
//
this.clearOutputStreamButton.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.clearOutputStreamButton.Location = new System.Drawing.Point(436, 52);
this.clearOutputStreamButton.Name = "clearOutputStreamButton";
this.clearOutputStreamButton.Size = new System.Drawing.Size(132, 23);
this.clearOutputStreamButton.TabIndex = 2;
this.clearOutputStreamButton.Text = "Спорожнити список";
this.clearOutputStreamButton.Click += new System.EventHandler(this.clearOutputStreamButton_Click);
//
// openFileButton
//
this.openFileButton.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.openFileButton.Location = new System.Drawing.Point(436, 20);
this.openFileButton.Name = "openFileButton";
this.openFileButton.Size = new System.Drawing.Size(132, 23);
this.openFileButton.TabIndex = 1;
this.openFileButton.Text = "Додати файл...";
this.openFileButton.Click += new System.EventHandler(this.openFileButton_Click);
//
// outputList
//
this.outputList.AllowColumnReorder = true;
this.outputList.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.outputList.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.columnHeader1,
this.columnHeader2,
this.columnHeader3});
this.outputList.FullRowSelect = true;
this.outputList.GridLines = true;
this.outputList.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable;
this.outputList.Location = new System.Drawing.Point(12, 20);
this.outputList.Name = "outputList";
this.outputList.Size = new System.Drawing.Size(406, 148);
this.outputList.TabIndex = 0;
this.outputList.UseCompatibleStateImageBehavior = false;
this.outputList.View = System.Windows.Forms.View.Details;
//
// columnHeader1
//
this.columnHeader1.Text = "Имя файла";
this.columnHeader1.Width = 193;
//
// columnHeader2
//
this.columnHeader2.Text = "Размер";
this.columnHeader2.Width = 70;
//
// columnHeader3
//
this.columnHeader3.Text = "Цифровая сигнатура";
this.columnHeader3.Width = 123;
//
// groupBox2
//
this.groupBox2.Controls.Add(this.storedSizeLabel);
this.groupBox2.Controls.Add(this.label2);
this.groupBox2.Controls.Add(this.inputLengthLabel);
this.groupBox2.Controls.Add(this.label4);
this.groupBox2.Controls.Add(this.closeButton);
this.groupBox2.Controls.Add(this.saveFileButton);
this.groupBox2.Controls.Add(this.openStreamButton);
this.groupBox2.Controls.Add(this.decryptPasswordEdit);
this.groupBox2.Controls.Add(this.decryptCheck);
this.groupBox2.Controls.Add(this.inputList);
this.groupBox2.Location = new System.Drawing.Point(8, 224);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(584, 199);
this.groupBox2.TabIndex = 1;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "Читання з двійкового потоку";
//
// storedSizeLabel
//
this.storedSizeLabel.Location = new System.Drawing.Point(340, 23);
this.storedSizeLabel.Name = "storedSizeLabel";
this.storedSizeLabel.Size = new System.Drawing.Size(96, 16);
this.storedSizeLabel.TabIndex = 3;
this.storedSizeLabel.Text = "(інформація відсутня)";
//
// label2
//
this.label2.Location = new System.Drawing.Point(280, 23);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(60, 16);
this.label2.TabIndex = 2;
this.label2.Text = "На диску:";
this.label2.TextAlign = System.Drawing.ContentAlignment.TopCenter;
//
// inputLengthLabel
//
this.inputLengthLabel.Location = new System.Drawing.Point(428, 132);
this.inputLengthLabel.Name = "inputLengthLabel";
this.inputLengthLabel.Size = new System.Drawing.Size(148, 16);
this.inputLengthLabel.TabIndex = 8;
this.inputLengthLabel.Text = "(інформація відсутня)";
this.inputLengthLabel.TextAlign = System.Drawing.ContentAlignment.TopCenter;
//
// label4
//
this.label4.Location = new System.Drawing.Point(448, 104);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(112, 28);
this.label4.TabIndex = 7;
this.label4.Text = "Загальний розмір даних потоку:";
this.label4.TextAlign = System.Drawing.ContentAlignment.TopCenter;
//
// closeButton
//
this.closeButton.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.closeButton.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.closeButton.Location = new System.Drawing.Point(440, 163);
this.closeButton.Name = "closeButton";
this.closeButton.Size = new System.Drawing.Size(128, 23);
this.closeButton.TabIndex = 9;
this.closeButton.Text = "Escape - Вихід";
this.closeButton.Click += new System.EventHandler(this.closeButton_Click);
//
// saveFileButton
//
this.saveFileButton.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.saveFileButton.Location = new System.Drawing.Point(436, 52);
this.saveFileButton.Name = "saveFileButton";
this.saveFileButton.Size = new System.Drawing.Size(132, 40);
this.saveFileButton.TabIndex = 6;
this.saveFileButton.Text = "Зберегти позначений файл файл...";
this.saveFileButton.Click += new System.EventHandler(this.saveFileButton_Click);
//
// openStreamButton
//
this.openStreamButton.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.openStreamButton.Location = new System.Drawing.Point(436, 20);
this.openStreamButton.Name = "openStreamButton";
this.openStreamButton.Size = new System.Drawing.Size(132, 23);
this.openStreamButton.TabIndex = 4;
this.openStreamButton.Text = "Завантажити з диска...";
this.openStreamButton.Click += new System.EventHandler(this.openStreamButton_Click);
//
// decryptPasswordEdit
//
this.decryptPasswordEdit.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.decryptPasswordEdit.Location = new System.Drawing.Point(184, 20);
this.decryptPasswordEdit.Name = "decryptPasswordEdit";
this.decryptPasswordEdit.Size = new System.Drawing.Size(84, 21);
this.decryptPasswordEdit.TabIndex = 1;
//
// decryptCheck
//
this.decryptCheck.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.decryptCheck.Location = new System.Drawing.Point(12, 20);
this.decryptCheck.Name = "decryptCheck";
this.decryptCheck.Size = new System.Drawing.Size(172, 21);
this.decryptCheck.TabIndex = 0;
this.decryptCheck.Text = "РОзшифрувати з паролем:";
//
// inputList
//
this.inputList.AllowColumnReorder = true;
this.inputList.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.inputList.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.columnHeader4,
this.columnHeader5,
this.columnHeader6});
this.inputList.FullRowSelect = true;
this.inputList.GridLines = true;
this.inputList.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable;
this.inputList.HideSelection = false;
this.inputList.Location = new System.Drawing.Point(12, 52);
this.inputList.Name = "inputList";
this.inputList.Size = new System.Drawing.Size(406, 134);
this.inputList.TabIndex = 5;
this.inputList.UseCompatibleStateImageBehavior = false;
this.inputList.View = System.Windows.Forms.View.Details;
//
// columnHeader4
//
this.columnHeader4.Text = "Имя файла";
this.columnHeader4.Width = 193;
//
// columnHeader5
//
this.columnHeader5.Text = "Размер";
this.columnHeader5.Width = 70;
//
// columnHeader6
//
this.columnHeader6.Text = "Цифровая сигнатура";
this.columnHeader6.Width = 123;
//
// openFileDialog
//
this.openFileDialog.Filter = "Все файлы (*.*)|*.*";
this.openFileDialog.Title = "Выберите файл для добавления в бинарный поток";
//
// saveStreamDialog
//
this.saveStreamDialog.Filter = "Все файлы (*.*)|*.*";
this.saveStreamDialog.Title = "Укажите файл для сохранения данных потока";
//
// openStreamDialog
//
this.openStreamDialog.Filter = "Все файлы (*.*)|*.*";
this.openStreamDialog.Title = "Выберите файл, содержащий данные бинарного потока";
//
// saveFileDialog
//
this.saveFileDialog.Filter = "Все файлы (*.*)|*.*";
this.saveFileDialog.Title = "Укажите имя выходного файла";
//
// MainForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 14);
this.CancelButton = this.closeButton;
this.ClientSize = new System.Drawing.Size(600, 423);
this.Controls.Add(this.groupBox2);
this.Controls.Add(this.groupBox1);
this.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204)));
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.MaximizeBox = false;
this.Name = "MainForm";
this.Text = "Лаба № 5 CAST 128";
this.Load += new System.EventHandler(this.MainForm_Load);
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
this.groupBox2.ResumeLayout(false);
this.groupBox2.PerformLayout();
this.ResumeLayout(false);
}
#endregion
[DllImport("KERNEL32.DLL", ExactSpelling = true, EntryPoint = "GetTickCount", CharSet = CharSet.Auto)]
private static extern uint GetTickCount();
private static void StartCount()
{
_tickCount = GetTickCount();
}
private static void StopCount()
{
_tickCount = GetTickCount() - _tickCount;
}
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
LoadConfig();
Application.Run(new MainForm());
SaveConfig();
}
private static void LoadConfig()
{
using (AcedRegistry config = new AcedRegistry(AcedBaseKey.CurrentUser,
DemoRegistryKey, false))
{
config.Get(cfgStreamFileName, ref _streamFileName);
_compressionLevel = (AcedCompressionLevel)config.GetDef(cfgCompressionLevel, 0);
}
}
private static void SaveConfig()
{
using (AcedRegistry config = new AcedRegistry(AcedBaseKey.CurrentUser,
DemoRegistryKey, true))
{
config.Put(cfgStreamFileName, _streamFileName);
config.Put(cfgCompressionLevel, (int)_compressionLevel);
}
}
private void MainForm_Load(object sender, System.EventArgs e)
{
_writer = new AcedMemoryWriter();
compressionLevelCombo.SelectedIndex = (int)_compressionLevel;
}
private void closeButton_Click(object sender, System.EventArgs e)
{
Close();
}
private void openFileButton_Click(object sender, System.EventArgs e)
{
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
Application.DoEvents();
OpenFile(openFileDialog.FileName);
}
}
private void clearOutputStreamButton_Click(object sender, System.EventArgs e)
{
ClearOutputStream();
}
private void saveStreamButton_Click(object sender, System.EventArgs e)
{
saveStreamDialog.FileName = _streamFileName;
if (saveStreamDialog.ShowDialog() == DialogResult.OK)
{
Application.DoEvents();
_streamFileName = saveStreamDialog.FileName;
_compressionLevel = (AcedCompressionLevel)compressionLevelCombo.SelectedIndex;
SaveStream();
MessageBox.Show("Бінарний потік розміром " + _streamLength.ToString() +
" байтів збережений у файлі:\n" + _streamFileName);
}
}
private void openStreamButton_Click(object sender, System.EventArgs e)
{
openStreamDialog.FileName = _streamFileName;
if (openStreamDialog.ShowDialog() == DialogResult.OK)
{
Application.DoEvents();
_streamFileName = openStreamDialog.FileName;
OpenStream();
if (_reader != null)
MessageBox.Show("Бінарний потік розміром " + _streamLength.ToString() +
" байтів прочитаний з файлу:\n" + _streamFileName);
}
}
private void saveFileButton_Click(object sender, System.EventArgs e)
{
ListViewItem item = null;
if (_reader != null)
{
ListView.SelectedListViewItemCollection sc = inputList.SelectedItems;
if (sc.Count > 0)
item = sc[0];
}
if (item != null)
{
saveFileDialog.FileName = item.Text;
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
Application.DoEvents();
SaveFile(saveFileDialog.FileName, item);
}
}
}
private void UpdateOutputLength()
{
outputLengthLabel.Text = _writer.Length.ToString() + " байтів";
}
private void UpdateInputLength()
{
if (_reader != null)
{
inputLengthLabel.Text = _reader.Size.ToString() + " байтів";
storedSizeLabel.Text = _streamLength.ToString() + " байтів";
}
else
{
inputLengthLabel.Text = "(інф. відсутня)";
storedSizeLabel.Text = "(інф. відсутня)";
}
}
private void OpenFile(string fileName)
{
FileStream fs = new FileStream(fileName, FileMode.Open);
fileName = fileName.Substring(fileName.LastIndexOf('\\') + 1);
int fileSize = (int)fs.Length;
_writer.WriteString(fileName);
_writer.WriteInt32(fileSize);
int startIndex = _writer.Length;
_writer.Skip(fileSize);
fs.Read(_writer.GetBuffer(), startIndex, fileSize);
fs.Close();
int[] rmd = AcedRipeMD.Compute(_writer.GetBuffer(), startIndex, fileSize);
ListViewItem item = new ListViewItem(fileName);
item.SubItems.Add(fileSize.ToString());
item.SubItems.Add(((uint)rmd[0]).ToString("X8") + ((uint)rmd[4]).ToString("X8"));
outputList.Items.Add(item);
UpdateOutputLength();
}
private void ClearOutputStream()
{
_writer.Reset();
outputList.Items.Clear();
UpdateOutputLength();
GC.Collect();
}
private void SaveStream()
{
StartCount();
byte[] bytes = _writer.ToArray(_compressionLevel, encryptCheck.Checked ?
AcedRipeMD.ToGuid(AcedRipeMD.Compute(encryptPasswordEdit.Text)) : Guid.Empty);
StopCount();
_streamLength