예제 #1
0
        private static string GetPassword(IConfigSection host)
        {
            var password = host.Get("password", false);

            if (string.IsNullOrEmpty(password))
            {
                return(password);
            }

            using (var cipher = new Aes256Cipher(Encoding.UTF8.GetBytes("he1sQWc8SSPpkdIA")))
            {
                if (password.StartsWith("enc:"))
                {
                    password = password.Substring(4);
                    var data = Convert.FromBase64String(password);
                    return(Encoding.UTF8.GetString(cipher.Decrypt(data)));
                }
                else
                {
                    var data = cipher.Encrypt(Encoding.UTF8.GetBytes(password));
                    host.Set("password", "enc:" + Convert.ToBase64String(data));
                    host.Config.Save();
                    return(password);
                }
            }
        }