示例#1
0
        private VpnDataModel Load(string path)
        {
            bool fileExists = File.Exists(path);

            if (!fileExists)
            {
                return(new VpnDataModel());
            }

            VpnDataModel model = null;

            try
            {
                byte[] file = File.ReadAllBytes(path);
                file = ProtectedDataHelper.Unprotect(file);
                using (var ms = new MemoryStream(file))
                {
                    var bf = new BinaryFormatter();
                    model = (VpnDataModel)bf.Deserialize(ms);
                }
            }
            catch (Exception e)
            {
                Util.TraceException("Error loading VpnData, restoring defaults ...", e);
            }
            return(model ?? new VpnDataModel());
        }
示例#2
0
 public void Save()
 {
     try
     {
         byte[] data;
         using (var ms = new MemoryStream())
         {
             var bf = new BinaryFormatter();
             bf.Serialize(ms, this.VpnDataModel);
             data = ms.ToArray();
         }
         data = ProtectedDataHelper.Protect(data);
         File.WriteAllBytes(this._path, data);
     }
     catch (Exception e)
     {
         Util.TraceException("Error while saving VpnData", e);
     }
 }
示例#3
0
    public static string EncryptString(string salt, string encrypted)
    {
        SecureString ss = encrypted.ToSecureString();

        return(ProtectedDataHelper.EncryptString(salt, ss));
    }
示例#4
0
 public static string DecryptString(string salt, string encrypted)
 {
     return(Unsafe.ToInsecureString(ProtectedDataHelper.DecryptString(salt, encrypted)));
 }