Ask Question

Name:
Title:
Your Question:

Answer Question

Name:
Your Answer:
User Submitted Source Code!


Description:
  3344
Language: C/C++
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Security.Cryptography;
using System.Management;
using System.IO;
 
namespace KeyFileGenerator_v1._0._0._0
{
    public partial class Form1 : Form
    {
        RijndaelManaged Rijndael;
 
        public Form1()
        {
            InitializeComponent();
            Rijndael = new RijndaelManaged();
            this.Load+=new EventHandler(Form1_Load);
            button1.Click+=new EventHandler(button1_Click);
        }
        void Form1_Load(object sender, EventArgs e)
        {
            textBox1.Focus();
            label1.Text = null;
            this.Text = "KeyFileGenerator for MON08 v1.0.0.0 by Yarik";
        }
        void button1_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(textBox1.Text))
            {
                label1.ForeColor = Color.Red;
                label1.Text = "Строка данных пуста!";
                return;
            }
            else
            {
                label1.Text = null;
                SaveFileDialog dialog = new SaveFileDialog();
                dialog.FileName = "keyfile";
                dialog.Filter = "dat files(*.dat)|*.dat";
                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    GetKeyFile(textBox1.Text, dialog.FileName);
                    MessageBox.Show("Файл ключа создан.", "Key Generator");
                }
            }
        }
        public void GetKeyFile(string inString,string path)
        {
            byte[] key = new byte[0x20];
            for (int i = 0; i <= 0x1f; i++)
                key[i] = 0x1f;
            Rijndael.Key = key;
            ICryptoTransform transformer = Rijndael.CreateEncryptor();
            FileStream fs = new FileStream(path, FileMode.Create);
            fs.Write(Rijndael.IV, 0, Rijndael.IV.Length);
            CryptoStream cs = new CryptoStream(fs, transformer, CryptoStreamMode.Write);
            StreamWriter sw = new StreamWriter(cs);
            sw.Write(inString);
            sw.Flush();
            cs.FlushFinalBlock();
            sw.Close();
        }
    }
}
          
Comments: