Beispiel #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());
        }
Beispiel #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);
     }
 }
Beispiel #3
0
    public static string EncryptString(string salt, string encrypted)
    {
        SecureString ss = encrypted.ToSecureString();

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