Exemple #1
0
		public int GetMaxClients()
		{
			using ( UtilDataAccess utilDataAccess = new UtilDataAccess() )
			{
				try
				{
					string encryptMaxClients = utilDataAccess.GetMaxClients();

					string maxClients = new DataProtector().InitInfoDecryp(encryptMaxClients);

					int retValue = Convert.ToInt32(maxClients.Substring(0,maxClients.IndexOf("#")));
					
					return retValue;

				}
				catch(Exception ex)
				{
					Util.WriteLog(ex.Message,Util.EXCEPTION_LOG_TITLE);
					return -1;
				}
			}
		}
        internal static async Task<string> ReadSecretFile(string filePath, DataProtector protector)
        {
            // Load file content
            byte[] encrypted;
            using (var file = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.None))
            {
                using (var ms = new MemoryStream())
                {
                    int read;
                    byte[] buffer = new byte[16 * 1024];
                    while ((read = await file.ReadAsync(buffer, 0, buffer.Length)) > 0)
                    {
                        ms.Write(buffer, 0, read);
                    }
                    encrypted = ms.ToArray();
                }
            }

            // Decrypt it
            return protector.UnprotectString(encrypted);
        }
 public static string UnprotectString(this DataProtector self, byte[] input)
 {
     return(Encoding.UTF8.GetString(
                self.Unprotect(input)));
 }
 internal static async Task WriteSecretFile(string filePath, string content, DataProtector protector)
 {
     var encrypted = protector.ProtectString(content);
     using (var file = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.None))
     {
         await file.WriteAsync(encrypted, 0, encrypted.Length);
     }
 }
 public static byte[] ProtectString(this DataProtector self, string input)
 {
     return(self.Protect(
                Encoding.UTF8.GetBytes(input)));
 }