|
@@ -0,0 +1,235 @@
|
|
|
+using System;
|
|
|
+using System.CodeDom.Compiler;
|
|
|
+using System.IO;
|
|
|
+using System.Linq;
|
|
|
+using System.Security.Cryptography;
|
|
|
+using System.Text;
|
|
|
+using System.Text.RegularExpressions;
|
|
|
+using System.Windows.Forms;
|
|
|
+using Microsoft.AspNet.Identity;
|
|
|
+
|
|
|
+namespace MiscToolSet
|
|
|
+{
|
|
|
+ public partial class MainForm : Form
|
|
|
+ {
|
|
|
+ private readonly RandomNumberGenerator _rng = RandomNumberGenerator.Create();
|
|
|
+ private readonly PasswordHasher _passwordHasher = new PasswordHasher();
|
|
|
+ private readonly MD5 _md5 = new MD5Cng();
|
|
|
+ private readonly Encoding _asciiEncoding = Encoding.ASCII;
|
|
|
+
|
|
|
+ [STAThread]
|
|
|
+ private static void Main()
|
|
|
+ {
|
|
|
+ Application.EnableVisualStyles();
|
|
|
+ Application.SetCompatibleTextRenderingDefault(false);
|
|
|
+ Application.Run(new MainForm());
|
|
|
+ }
|
|
|
+
|
|
|
+ public MainForm()
|
|
|
+ {
|
|
|
+ InitializeComponent();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void Md5HasherUpperCaseCheckBox_CheckedChanged(object sender, EventArgs e)
|
|
|
+ {
|
|
|
+ MD5HasherInputTextBox_TextChanged(null, null);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void MD5HasherInputTextBox_TextChanged(object sender, EventArgs e)
|
|
|
+ {
|
|
|
+ var fmt = Md5HasherUpperCaseCheckBox.Checked ? "X2" : "x2";
|
|
|
+ Md5HasherOutputTextBox.Text = string.Join("", _md5.ComputeHash(Encoding.UTF8.GetBytes(MD5HasherInputTextBox.Text)).Select(p => p.ToString(fmt)));
|
|
|
+ }
|
|
|
+
|
|
|
+ private void txtToPasswordHash_TextChanged(object sender, System.EventArgs e)
|
|
|
+ {
|
|
|
+ PasswordHasherOutputTextBox.Text = _passwordHasher.HashPassword(PasswordHasherInputTextBox.Text);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void txtResultOfPasswordHash_MouseDoubleClick(object sender, MouseEventArgs e)
|
|
|
+ {
|
|
|
+ PasswordHasherOutputTextBox.SelectAll();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void btnNewGuid_Click(object sender, EventArgs e)
|
|
|
+ {
|
|
|
+ var g = Guid.NewGuid();
|
|
|
+ GuidGeneratorResultDTextBox.Text = g.ToString("D").ProcessWhen(UpperCaseCheckBox.Checked, p => p.ToUpper());
|
|
|
+ GuidGeneratorResultNTextBox.Text = g.ToString("N").ProcessWhen(UpperCaseCheckBox.Checked, p => p.ToUpper());
|
|
|
+ GuidGeneratorResultAttributeTextBox.Text = $"[Guid(\"{g.ToString("D").ProcessWhen(UpperCaseCheckBox.Checked, p => p.ToUpper()) }\")]";
|
|
|
+ GuidGeneratorResultNewTextBox.Text = $"new Guid(\"{g.ToString("D").ProcessWhen(UpperCaseCheckBox.Checked, p => p.ToUpper())}\")";
|
|
|
+ }
|
|
|
+
|
|
|
+ private void btnCpN_Click(object sender, EventArgs e) => Clipboard.SetText(GuidGeneratorResultNTextBox.Text);
|
|
|
+
|
|
|
+ private void btnCpD_Click(object sender, EventArgs e) => Clipboard.SetText(GuidGeneratorResultDTextBox.Text);
|
|
|
+
|
|
|
+ private void btnCpA_Click(object sender, EventArgs e) => Clipboard.SetText(GuidGeneratorResultAttributeTextBox.Text);
|
|
|
+
|
|
|
+ private void GuidGeneratorCopyNewButton_Click(object sender, EventArgs e) => Clipboard.SetText(GuidGeneratorResultNewTextBox.Text);
|
|
|
+
|
|
|
+ private void NewMachineKeyButton_Click(object sender, EventArgs e)
|
|
|
+ {
|
|
|
+ var rng = new RNGCryptoServiceProvider();
|
|
|
+ string CreateKey(int numBytes)
|
|
|
+ {
|
|
|
+ var buff = new byte[numBytes];
|
|
|
+ rng.GetBytes(buff);
|
|
|
+ return string.Join("", buff.Select(p => $"{p:X2}"));
|
|
|
+ }
|
|
|
+
|
|
|
+ MachineKeyResult.Text =
|
|
|
+ $"<machineKey" +
|
|
|
+ $" validationKey=\"{CreateKey(64)}\"" +
|
|
|
+ $" decryptionKey=\"{CreateKey(24)}\"" +
|
|
|
+ $" decryption=\"3DES\"" +
|
|
|
+ $" validation=\"3DES\" />";
|
|
|
+ }
|
|
|
+
|
|
|
+ private void CopyMachineKeyButton_Click(object sender, EventArgs e)
|
|
|
+ {
|
|
|
+ Clipboard.SetText(MachineKeyResult.Text);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void PasswordGenerateButton_Click(object sender, EventArgs e)
|
|
|
+ {
|
|
|
+ int GetIntRandomly()
|
|
|
+ {
|
|
|
+ var buf = new byte[4];
|
|
|
+ _rng.GetBytes(buf);
|
|
|
+ return BitConverter.ToInt32(buf, 0);
|
|
|
+ }
|
|
|
+
|
|
|
+ var stringBuilder = new StringBuilder();
|
|
|
+ if (PasswordGenerateIncludeUpperCaseCheckBox.Checked) stringBuilder.Append(Enumerable.Range('A', 'Z' - 'A' + 1).Select(p => (char)p).ToArray());
|
|
|
+ if (PasswordGenerateIncludeLowerCaseCheckBox.Checked) stringBuilder.Append(Enumerable.Range('a', 'z' - 'a' + 1).Select(p => (char)p).ToArray());
|
|
|
+ if (PasswordGenerateIncludeNumberCheckBox.Checked) stringBuilder.Append(Enumerable.Range('0', '9' - '0' + 1).Select(p => (char)p).ToArray());
|
|
|
+ if (PasswordGenerateIncludeSymbolCheckBox.Checked) stringBuilder.Append("!@#$%&*");
|
|
|
+
|
|
|
+ var charPool = stringBuilder.ToString();
|
|
|
+ string GetRandomString()
|
|
|
+ {
|
|
|
+ return new string(
|
|
|
+ Enumerable.Range(0, (int)PasswordGenerateLengthUpDownBox.Value)
|
|
|
+ .Select(p => charPool[Math.Abs(GetIntRandomly() % charPool.Length)])
|
|
|
+ .ToArray()
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ string HashString(string str)
|
|
|
+ {
|
|
|
+ if (PasswordGenerateUseMd5RadioButton.Checked)
|
|
|
+ {
|
|
|
+ var fmt = PasswordGeneratorHashUseUpperCaseCheckBox.Checked ? "X2" : "x2";
|
|
|
+ return string.Join("", _md5.ComputeHash(_asciiEncoding.GetBytes(str)).Select(p => p.ToString(fmt)));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (PasswordGenerateUsePasswordHasherRadioButton.Checked)
|
|
|
+ {
|
|
|
+ return _passwordHasher.HashPassword(str);
|
|
|
+ }
|
|
|
+
|
|
|
+ throw new NotImplementedException();
|
|
|
+ }
|
|
|
+
|
|
|
+ PasswordGenerateResultRichTextBox.Clear();
|
|
|
+ for (var i = 0; i < PasswordGenerateNumberUpDownBox.Value; i++)
|
|
|
+ {
|
|
|
+ var str = GetRandomString();
|
|
|
+
|
|
|
+ PasswordGenerateResultRichTextBox.AppendText($"{str} {HashString(str)}{Environment.NewLine}");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void DropToBase64Label_DragEnter(object sender, DragEventArgs e)
|
|
|
+ {
|
|
|
+ e.Effect = e.Data.GetDataPresent(DataFormats.FileDrop)
|
|
|
+ ? DragDropEffects.Copy
|
|
|
+ : DragDropEffects.None;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void DropToBase64Label_DragDrop(object sender, DragEventArgs e)
|
|
|
+ {
|
|
|
+ var files = (string[])e.Data.GetData(DataFormats.FileDrop);
|
|
|
+
|
|
|
+ DropToBase64FileNameLabel.Text = Path.GetFileName(files[0]);
|
|
|
+
|
|
|
+ var bytes = File.ReadAllBytes(files[0]);
|
|
|
+ var base64String = Convert.ToBase64String(bytes, Base64FormattingOptions.None);
|
|
|
+ DropToBase64TextBox.Text = DataUrlCheckBox.Checked
|
|
|
+ ? $"data:{DataUrlMimeTypeTextBox.Text};base64,{base64String}"
|
|
|
+ : base64String;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void CopyBase64Button_Click(object sender, EventArgs e)
|
|
|
+ {
|
|
|
+ Clipboard.SetText(DropToBase64TextBox.Text);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void BulkNewGuidButton_Click(object sender, EventArgs e)
|
|
|
+ {
|
|
|
+ var length = ((int)BulkNewGuidUpDown.Value);
|
|
|
+ for (var i = 0; i < length; i++)
|
|
|
+ {
|
|
|
+ var guid = Guid.NewGuid();
|
|
|
+
|
|
|
+ if (NormalBulkNewGuidRadioButton.Checked) BulkNewGuidTextBox.AppendText($"{guid:D}{Environment.NewLine}".ProcessWhen(UpperCaseCheckBox.Checked, p => p.ToUpper()));
|
|
|
+ if (CtorBulkNewGuidRadioButton.Checked) BulkNewGuidTextBox.AppendText($"new Guid(\"{$"{guid:D}".ProcessWhen(UpperCaseCheckBox.Checked, p => p.ToUpper())}\");{Environment.NewLine}");
|
|
|
+ if (AttrBulkNewGuidRadioButton.Checked) BulkNewGuidTextBox.AppendText($"[Guid(\"{$"{guid:D}".ProcessWhen(UpperCaseCheckBox.Checked, p => p.ToUpper())}\"]{Environment.NewLine}");
|
|
|
+ if (NumberBulkNewGuidRadioButton.Checked) BulkNewGuidTextBox.AppendText($"{guid:N}{Environment.NewLine}".ProcessWhen(UpperCaseCheckBox.Checked, p => p.ToUpper()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void MagicHuntingButton_Click(object sender, EventArgs e)
|
|
|
+ {
|
|
|
+ var magicPattern = new Regex(MagicPatternText.Text, RegexOptions.Compiled);
|
|
|
+
|
|
|
+ var dicCollect = new System.Collections.Generic.Dictionary<string, string>();
|
|
|
+
|
|
|
+ CodeConvertTextBox.Text = magicPattern.Replace(CodeInputTextBox.Text, match =>
|
|
|
+ {
|
|
|
+ var identity = match.Groups[1].Value;
|
|
|
+
|
|
|
+ if (false == IdentifierChecker.Valid(identity)) return match.Value;
|
|
|
+ if (false == dicCollect.ContainsKey(identity)) dicCollect[identity] = match.Result(CollectPatternTextBox.Text);
|
|
|
+
|
|
|
+ return match.Result(ConvertPatternTextBox.Text);
|
|
|
+ });
|
|
|
+
|
|
|
+ CodeCollectTextBox.Text =
|
|
|
+ "private static class Identities {"
|
|
|
+ + Environment.NewLine + "// ReSharper disable InconsistentNaming" + Environment.NewLine;
|
|
|
+
|
|
|
+ CodeCollectTextBox.Text += string.Join(Environment.NewLine, dicCollect.Values.OrderBy(p => p));
|
|
|
+
|
|
|
+ CodeCollectTextBox.Text +=
|
|
|
+ Environment.NewLine
|
|
|
+ + "// ReSharper restore InconsistentNaming" + Environment.NewLine
|
|
|
+ + "}";
|
|
|
+ }
|
|
|
+
|
|
|
+ private void RsaKeyGenerateButton_Click(object sender, EventArgs e)
|
|
|
+ {
|
|
|
+ // thanks to dotblogs.com.tw/supershowwei/2015/12/23/160510
|
|
|
+ // docs.microsoft.com/en-us/dotnet/api/system.security.cryptography.rsacryptoserviceprovider.keysize#remarks
|
|
|
+ var rsa = new RSACryptoServiceProvider((int)RsaKeySizeUpDown.Value);
|
|
|
+ RsaPrivateKeyTextBox.Text = rsa.ToXmlString(true);
|
|
|
+ RsaPublicKeyTextBox.Text = rsa.ToXmlString(false);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ internal static class CommonExtensionMetond
|
|
|
+ {
|
|
|
+ public static T ProcessWhen<T>(this T me, bool when, Func<T, T> process)
|
|
|
+ {
|
|
|
+ return when ? process(me) : me;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ internal static class IdentifierChecker
|
|
|
+ {
|
|
|
+ private static readonly CodeDomProvider Provider = CodeDomProvider.CreateProvider("C#");
|
|
|
+
|
|
|
+ public static bool Valid(string word) => Provider.IsValidIdentifier(word);
|
|
|
+ };
|
|
|
+}
|