public static bool CreateDecryptedImages(string sessionId)
 {
     string[] filePaths = GetEncryptedImagePaths(sessionId);
     foreach (string path in filePaths)
     {
         try
         {
             byte[] fileBytes = File.ReadAllBytes(path);
             byte[] decrypted = CacheEncrypter.DecryptData(fileBytes, CommonConst.DES_KEY);
             CacheUtils.ByteToImage(decrypted).Save(string.Format("{0}\\{1}\\{2}", CommonConst.LOCAL_CACHE_PATH,
                                                                  sessionId, Path.GetFileName(path).Replace(CommonConst.ENCR_IMG_EXT, CommonConst.DECR_IMG_EXT)));
         }
         catch { }
     }
     return(true);
 }
 public static bool CreateEncryptedImages(string sessionId)
 {
     try
     {
         string[] filePaths = GetDecryptedImagePaths(sessionId);
         foreach (string path in filePaths)
         {
             byte[] fileBytes = File.ReadAllBytes(path);
             byte[] encrypted = CacheEncrypter.EncryptData(fileBytes, CommonConst.DES_KEY);
             File.WriteAllBytes(string.Format("{0}\\{1}\\{2}", CommonConst.LOCAL_CACHE_PATH,
                                              sessionId, Path.GetFileName(path).Replace(CommonConst.DECR_IMG_EXT, CommonConst.ENCR_IMG_EXT)), encrypted);
         }
     }
     catch { return(false); }
     return(true);
 }
        public static bool DecryptData(string sessionId)
        {
            if (!File.Exists(GetDataEncryptedFilePath(sessionId)))
            {
                return(true);
            }

            try
            {
                byte[] encrypted = File.ReadAllBytes(GetDataEncryptedFilePath(sessionId));
                byte[] decrypted = CacheEncrypter.DecryptData(encrypted, CommonConst.DES_KEY);
                File.WriteAllText(GetDataDecryptedFilePath(sessionId), CacheUtils.GetString(decrypted));
            } catch { }

            return(true);
        }
        public static bool EncryptData(string sessionId)
        {
            if (!File.Exists(GetDataDecryptedFilePath(sessionId)))
            {
                return(true);
            }

            try
            {
                string data      = File.ReadAllText(GetDataDecryptedFilePath(sessionId));
                byte[] encrypted = CacheEncrypter.EncryptData(CacheUtils.GetBytes(data), CommonConst.DES_KEY);
                File.WriteAllBytes(GetDataEncryptedFilePath(sessionId), encrypted);
            }
            catch { return(true); }
            return(true);
        }
 public static bool SaveImage(Image image, string imageName, string sessionId, bool encrypt)
 {
     if (!Directory.Exists(CacheUtils.GetFullPathToSession(sessionId)))
     {
         Directory.CreateDirectory(CacheUtils.GetFullPathToSession(sessionId));
     }
     if (encrypt)
     {
         byte[] encrypted = CacheEncrypter.EncryptData(CacheUtils.ImageToByte(image), CommonConst.DES_KEY);
         File.WriteAllBytes(string.Format("{0}{1}",
                                          CacheUtils.GetFullPathToFile(imageName, sessionId), CommonConst.ENCR_IMG_EXT), encrypted);
     }
     else
     {
         image.Save(string.Format("{0}{1}",
                                  CacheUtils.GetFullPathToFile(imageName, sessionId), CommonConst.DECR_IMG_EXT));
     }
     return(true);
 }
        public static bool SaveData(IList <string> data, string sessionId, bool encrypt)
        {
            StringBuilder finalData = new StringBuilder();

            foreach (string line in data)
            {
                finalData.Append(line);
                finalData.Append(Environment.NewLine);
            }

            if (encrypt)
            {
                byte[] encrypted = CacheEncrypter.EncryptData(CacheUtils.GetBytes(finalData.ToString()), CommonConst.DES_KEY);
                File.WriteAllBytes(GetDataEncryptedFilePath(sessionId), encrypted);
            }
            else
            {
                File.WriteAllText(GetDataDecryptedFilePath(sessionId), finalData.ToString());
            }

            return(true);
        }