#region Project
#region Using's
using System;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
#endregion
#region Code
namespace Key_Gen
{
public partial class Form1 : Form
{
#region Main
public Form1()
{
InitializeComponent();
}
private static string Hex2String(byte[] values)
{
return BitConverter.ToString(values);
}
private void Generated(object sender, EventArgs e)
{
try
{
int encrypt1 = 10;
int encrypt2 = 99;
Random r = new Random();
byte[] val3 = new Byte[8];
Int32 val = r.Next(encrypt1, encrypt2);
r.NextBytes(val3);
string input = Hex2String(val3).ToString();
txtKey.Text = val + "-" + input + "-" + val + "-" + input;
if (txtKey.Text.Count() >= 20)
{
MessageBox.Show("You have successfully generated a key \n " + txtKey.Text, "Generated", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else if(txtKey.Text.Count() < 20)
{
MessageBox.Show("You have failed to generated a key ", "Failed to Generate", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
catch(Exception ex)
{
MessageBox.Show("Failed to Generate : Original Error : \n" + ex, "Exception", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
private void Export(object sender, EventArgs e)
{
using (SaveFileDialog std = new SaveFileDialog() { Filter = "Text Documents | *.txt", ValidateNames = true })
{
if (std.ShowDialog() == DialogResult.OK)
{
using (TextWriter tw = new StreamWriter(new FileStream(std.FileName, FileMode.Create), Encoding.ASCII))
{
tw.WriteLine("Key Generated:\t" + txtKey.Text);
}
}
}
}
#endregion
}
}
#endregion
#endregion
Copyright © 2024, NextGenUpdate.
All Rights Reserved.