Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #using <System.Security.dll>
- namespace Project_2 {
- using namespace System;
- using namespace System::ComponentModel;
- using namespace System::Collections;
- using namespace System::Windows::Forms;
- using namespace System::Data;
- using namespace System::Drawing;
- using namespace System::IO;
- using namespace System::Security::Cryptography;
- /// <summary>
- /// Сводка для Form1
- ///
- /// Внимание! При изменении имени этого класса необходимо также изменить
- /// свойство имени файла ресурсов ("Resource File Name") для средства компиляции управляемого ресурса,
- /// связанного со всеми файлами с расширением .resx, от которых зависит данный класс. В противном случае,
- /// конструкторы не смогут правильно работать с локализованными
- /// ресурсами, сопоставленными данной форме.
- /// </summary>
- public ref class Form1 : public System::Windows::Forms::Form
- {
- public:
- Form1(void)
- {
- InitializeComponent();
- //
- //TODO: добавьте код конструктора
- //
- }
- protected:
- /// <summary>
- /// Освободить все используемые ресурсы.
- /// </summary>
- ~Form1()
- {
- if (components)
- {
- delete components;
- }
- }
- private: System::Windows::Forms::TextBox^ textBox1;
- private: System::Windows::Forms::Button^ overview;
- private: System::Windows::Forms::TextBox^ hash;
- private: System::Windows::Forms::Label^ md5_lbl;
- private: System::Windows::Forms::Button^ encrypt;
- private: System::Windows::Forms::ProgressBar^ progressBar1;
- private: System::Windows::Forms::Button^ decrypt;
- private: System::Windows::Forms::Label^ label1;
- private: System::Windows::Forms::TextBox^ password;
- protected:
- private:
- /// <summary>
- /// Требуется переменная конструктора.
- /// </summary>
- System::ComponentModel::Container ^components;
- #pragma region Windows Form Designer generated code
- /// <summary>
- /// Обязательный метод для поддержки конструктора - не изменяйте
- /// содержимое данного метода при помощи редактора кода.
- /// </summary>
- void InitializeComponent(void)
- {
- this->textBox1 = (gcnew System::Windows::Forms::TextBox());
- this->overview = (gcnew System::Windows::Forms::Button());
- this->hash = (gcnew System::Windows::Forms::TextBox());
- this->md5_lbl = (gcnew System::Windows::Forms::Label());
- this->encrypt = (gcnew System::Windows::Forms::Button());
- this->progressBar1 = (gcnew System::Windows::Forms::ProgressBar());
- this->decrypt = (gcnew System::Windows::Forms::Button());
- this->label1 = (gcnew System::Windows::Forms::Label());
- this->password = (gcnew System::Windows::Forms::TextBox());
- this->SuspendLayout();
- //
- // textBox1
- //
- this->textBox1->Location = System::Drawing::Point(12, 12);
- this->textBox1->Name = L"textBox1";
- this->textBox1->Size = System::Drawing::Size(216, 20);
- this->textBox1->TabIndex = 0;
- //
- // overview
- //
- this->overview->Location = System::Drawing::Point(235, 10);
- this->overview->Name = L"overview";
- this->overview->Size = System::Drawing::Size(75, 23);
- this->overview->TabIndex = 1;
- this->overview->Text = L"overview";
- this->overview->UseVisualStyleBackColor = true;
- this->overview->Click += gcnew System::EventHandler(this, &Form1::overview_Click);
- //
- // hash
- //
- this->hash->Font = (gcnew System::Drawing::Font(L"Microsoft YaHei", 8.25F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
- static_cast<System::Byte>(204)));
- this->hash->Location = System::Drawing::Point(13, 64);
- this->hash->Name = L"hash";
- this->hash->Size = System::Drawing::Size(297, 22);
- this->hash->TabIndex = 2;
- this->hash->TextChanged += gcnew System::EventHandler(this, &Form1::hash_TextChanged);
- //
- // md5_lbl
- //
- this->md5_lbl->AutoSize = true;
- this->md5_lbl->Font = (gcnew System::Drawing::Font(L"Microsoft YaHei", 9.75F, static_cast<System::Drawing::FontStyle>((System::Drawing::FontStyle::Bold | System::Drawing::FontStyle::Italic)),
- System::Drawing::GraphicsUnit::Point, static_cast<System::Byte>(204)));
- this->md5_lbl->Location = System::Drawing::Point(13, 39);
- this->md5_lbl->Name = L"md5_lbl";
- this->md5_lbl->Size = System::Drawing::Size(43, 19);
- this->md5_lbl->TabIndex = 3;
- this->md5_lbl->Text = L"md5:";
- //
- // encrypt
- //
- this->encrypt->Location = System::Drawing::Point(13, 144);
- this->encrypt->Name = L"encrypt";
- this->encrypt->Size = System::Drawing::Size(75, 23);
- this->encrypt->TabIndex = 4;
- this->encrypt->Text = L"Encrypt";
- this->encrypt->UseVisualStyleBackColor = true;
- this->encrypt->Click += gcnew System::EventHandler(this, &Form1::encrypt_Click);
- //
- // progressBar1
- //
- this->progressBar1->Location = System::Drawing::Point(104, 144);
- this->progressBar1->Name = L"progressBar1";
- this->progressBar1->Size = System::Drawing::Size(206, 23);
- this->progressBar1->Style = System::Windows::Forms::ProgressBarStyle::Continuous;
- this->progressBar1->TabIndex = 5;
- //
- // decrypt
- //
- this->decrypt->Location = System::Drawing::Point(13, 184);
- this->decrypt->Name = L"decrypt";
- this->decrypt->Size = System::Drawing::Size(75, 23);
- this->decrypt->TabIndex = 6;
- this->decrypt->Text = L"Decrypt";
- this->decrypt->UseVisualStyleBackColor = true;
- this->decrypt->Click += gcnew System::EventHandler(this, &Form1::decrypt_Click);
- //
- // label1
- //
- this->label1->AutoSize = true;
- this->label1->Location = System::Drawing::Point(21, 115);
- this->label1->Name = L"label1";
- this->label1->Size = System::Drawing::Size(53, 13);
- this->label1->TabIndex = 7;
- this->label1->Text = L"Password";
- //
- // password
- //
- this->password->Location = System::Drawing::Point(104, 115);
- this->password->Name = L"password";
- this->password->Size = System::Drawing::Size(206, 20);
- this->password->TabIndex = 8;
- //
- // Form1
- //
- this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
- this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
- this->ClientSize = System::Drawing::Size(325, 261);
- this->Controls->Add(this->password);
- this->Controls->Add(this->label1);
- this->Controls->Add(this->decrypt);
- this->Controls->Add(this->progressBar1);
- this->Controls->Add(this->encrypt);
- this->Controls->Add(this->md5_lbl);
- this->Controls->Add(this->hash);
- this->Controls->Add(this->overview);
- this->Controls->Add(this->textBox1);
- this->Name = L"Form1";
- this->Text = L"Form1";
- this->ResumeLayout(false);
- this->PerformLayout();
- }
- #pragma endregion
- private: System::Void overview_Click(System::Object^ sender, System::EventArgs^ e) {
- OpenFileDialog^ fileDlg = gcnew OpenFileDialog;
- fileDlg->InitialDirectory = Environment::CurrentDirectory;
- if (fileDlg->ShowDialog() == System::Windows::Forms::DialogResult::OK) {
- this->textBox1->Text = fileDlg->FileName;
- }
- HashAlgorithm^ md5 = gcnew MD5CryptoServiceProvider;
- FileStream^ fptr = gcnew FileStream(this->textBox1->Text, FileMode::Open);
- array<Byte>^ result;
- result = md5->ComputeHash(fptr);
- fptr->Close();
- this->hash->Text = "";
- for (Int32 i = 0; i < result->Length; i++) {
- this->hash->Text += Convert::ToString(result[i]) + " ";
- }
- }
- private: System::Void hash_TextChanged(System::Object^ sender, System::EventArgs^ e) {
- }
- private: System::Void encrypt_Click(System::Object^ sender, System::EventArgs^ e) {
- OpenFileDialog^ fileDlg = gcnew OpenFileDialog;
- OpenFileDialog^ fileDlg_write = gcnew OpenFileDialog;
- fileDlg->InitialDirectory = Environment::CurrentDirectory;
- if (fileDlg->ShowDialog() == System::Windows::Forms::DialogResult::OK) {
- FileStream^ fptr = gcnew FileStream(fileDlg->FileName, FileMode::Open);
- FileStream^ fptr_write = gcnew FileStream(fileDlg->FileName + ".enc", FileMode::Create);
- try {
- array<Byte>^ pwd = gcnew array<Byte>(8) {43,88,12,43,65,78,54,121}; // Key
- array<Byte>^ initVector = gcnew array<Byte>(8) {76,34,54,76,12,43,65,76}; // IV
- SymmetricAlgorithm^ Des = gcnew DESCryptoServiceProvider;
- for (Int32 j = 0; j < Des->Key->Length; j++) {
- pwd[j] = Convert::ToByte(Convert::ToInt32(Covert::ToChar(this->password->Text[j % this->password->TextLength])) % 256);
- }
- Des->Key = pwd;
- Des->IV = initVector;
- CryptoStream^ enc_stream = gcnew CryptoStream (
- fptr_write,
- Des->CreateEncryptor(Des->Key, Des->IV),
- CryptoStreamMode::Write
- );
- Int32 readlen = 0;
- Int32 totallen = fptr->Length;
- this->progressBar1->Value = 0;
- this->progressBar1->Maximum = fptr->Length;
- Int32 len = 0;
- array<Byte>^ bin = gcnew array<Byte>(1024);
- while (readlen < totallen) {
- len = fptr->Read(bin, 0, 1024);
- enc_stream->Write(bin, 0, len);
- readlen += len;
- this->progressBar1->Value = readlen;
- Application::DoEvents();
- }
- enc_stream->Close();
- }
- finally {
- fptr->Close();
- fptr_write->Close();
- }
- }
- }
- private: System::Void decrypt_Click(System::Object^ sender, System::EventArgs^ e) {
- OpenFileDialog^ fileDlg = gcnew OpenFileDialog;
- OpenFileDialog^ fileDlg_write = gcnew OpenFileDialog;
- fileDlg->InitialDirectory = Environment::CurrentDirectory;
- if (fileDlg->ShowDialog() == System::Windows::Forms::DialogResult::OK) {
- FileStream^ fptr = gcnew FileStream(fileDlg->FileName, FileMode::Open);
- FileStream^ fptr_write = gcnew FileStream(fileDlg->FileName + ".jpeg", FileMode::Create);
- try {
- array<Byte>^ pwd = gcnew array<Byte>(8) {43,88,12,43,65,78,54,121}; // Key
- array<Byte>^ initVector = gcnew array<Byte>(8) {76,34,54,76,12,43,65,76}; // IV
- SymmetricAlgorithm^ Des = gcnew DESCryptoServiceProvider;
- for (Int32 j = 0; j < Des->Key->Length; j++) {
- pwd[j] = Convert::ToByte(Convert::ToInt32(Covert::ToChar(this->password->Text[j % this->password->TextLength])) % 256);
- }
- Des->Key = pwd;
- Des->IV = initVector;
- CryptoStream^ enc_stream = gcnew CryptoStream (
- fptr_write,
- Des->CreateDecryptor(Des->Key, Des->IV),
- CryptoStreamMode::Write
- );
- Int32 readlen = 0;
- Int32 totallen = fptr->Length;
- this->progressBar1->Value = 0;
- this->progressBar1->Maximum = fptr->Length;
- Int32 len = 0;
- array<Byte>^ bin = gcnew array<Byte>(1024);
- while (readlen < totallen) {
- len = fptr->Read(bin, 0, 1024);
- enc_stream->Write(bin, 0, len);
- readlen += len;
- this->progressBar1->Value = readlen;
- Application::DoEvents();
- }
- enc_stream->Close();
- }
- finally {
- fptr->Close();
- fptr_write->Close();
- }
- }
- }
- };
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement