using Org.BouncyCastle.Crypto; using Org.BouncyCastle.Crypto.IO; using Org.BouncyCastle.Crypto.Parameters; using Org.BouncyCastle.Security; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.IO; using System.Linq; using System.Security.Cryptography; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace PasswortEncryptor { public partial class MainForm : Form { private static string MemoryMasterKey = "!ZEqy2Zsb#VK6<8`H6;W~VxJ$r:w.{ffzwDt== 0) { dataStream.WriteByte((byte)ch); } } } plainTextBuffer = dataStream.ToArray(); result = Encoding.UTF8.GetString(plainTextBuffer); } } catch { result = null; } return result; } public static byte[] GetKey(string password) { byte[] result = null; try { if (!string.IsNullOrEmpty(password)) { if (password.Length < 32) { password = password.PadRight(32, '@'); } else if (password.Length > 32) { password = MD5Encrypt(password); } result = Encoding.ASCII.GetBytes(password); } } catch (Exception ex) { } return result; } public static string MD5Encrypt(string value) { string result = null; try { byte[] bytes = Encoding.UTF8.GetBytes(value); using (System.Security.Cryptography.MD5 hash = System.Security.Cryptography.MD5.Create()) { byte[] hashedInputBytes = hash.ComputeHash(bytes); StringBuilder hashedInputStringBuilder = new StringBuilder(128); foreach (var b in hashedInputBytes) { hashedInputStringBuilder.Append(b.ToString("X2")); } result = hashedInputStringBuilder.ToString().ToLower(); } } catch { result = null; } return result; } private void cbxTemplate_SelectedIndexChanged(object sender, EventArgs e) { if(cbxTemplate.SelectedIndex == 1) { txtInput.Text = "Server=myServer;Uid=myUser;Database=myDatabase;Pwd=myPassword;SSLMode=None;Charset=utf8mb4"; } } private void btnEncrypt_Click(object sender, EventArgs e) { try { txtOutput.Text = Encrypt(txtInput.Text); } catch (Exception ex) { txtOutput.Text = ex.Message; } } } }