Ну как вариант шифровать пароль в приложении, а потом уже его в базу записывать. Вот когда-то писал для себя, может поможет
| Код | public class Crypt { /// <summary> /// ключевое слово /// </summary> private static string word = "bla-bla-bla"; private static string password = null;
public static void LoadDefaultPassword() { SetPassword("administrator"); }
public static string GetPassword() { if (password == null) { StreamReader sr = File.OpenText(Application.StartupPath + @"\password.pass"); password = Decrypt(sr.ReadLine()); sr.Close(); } return password; }
public static void SetPassword(string newPassword) { StreamWriter sw = File.CreateText(Application.StartupPath + @"\password.pass"); sw.WriteLine(Encrypt(newPassword)); password = newPassword; sw.Close(); }
private static byte[] Encrypt(byte[] data) { SymmetricAlgorithm sa = Rijndael.Create(); ICryptoTransform ct = sa.CreateEncryptor( (new PasswordDeriveBytes(word, null)).GetBytes(16), new byte[16]); MemoryStream ms = new MemoryStream(); CryptoStream cs = new CryptoStream(ms, ct, CryptoStreamMode.Write);
cs.Write(data, 0, data.Length); cs.FlushFinalBlock();
return ms.ToArray(); }
public static string Encrypt (string data) { return Convert.ToBase64String(Encrypt(Encoding.UTF8.GetBytes(data))); }
public static string Decrypt (string data) { CryptoStream cs = InternalDecrypt(Convert.FromBase64String(data)); StreamReader sr = new StreamReader(cs); return sr.ReadToEnd(); }
private static CryptoStream InternalDecrypt (byte[] data) { SymmetricAlgorithm sa = Rijndael.Create(); ICryptoTransform ct = sa.CreateDecryptor( (new PasswordDeriveBytes(word, null)).GetBytes(16), new byte[16]); MemoryStream ms = new MemoryStream(data); return new CryptoStream(ms, ct, CryptoStreamMode.Read); } }
|
|