public void ProcessFile(string path, string password, long totalSize) { var webPath = config.WebServer.WebFilePath; var tempFolderPath = webPath + "temp\\"; if (!Directory.Exists(tempFolderPath)) { Directory.CreateDirectory(tempFolderPath); } var file = new FileInfo(path); file.Directory?.Create(); // If the directory already exists, this method does nothing. var fileName = Path.GetFileName(path); var ip = NetworkService.GetAddress(); var port = config.WebServer.WebServerPort; var passwordBytes = Encoding.UTF8.GetBytes(password); if (File.Exists(path)) { try { var tempPath = Path.Combine(tempFolderPath, fileName); UlteriusAes.EncryptFile(passwordBytes, path, tempPath); var tempWebPath = $"http://{ip}:{port}/temp/{fileName}"; var downloadData = new { tempWebPath, totalSize }; _builder.WriteMessage(downloadData); } catch (Exception e) { var exceptionData = new { error = true, message = e.Message }; _builder.WriteMessage(exceptionData); } } else { var errorData = new { error = true, message = "Unable to encrypt file" }; _builder.WriteMessage(errorData); } }
public byte[] SerializeFile(WebSocket client, string password, byte[] data) { try { var passwordBytes = Encoding.UTF8.GetBytes(password); return(UlteriusAes.EncryptFile(data, passwordBytes)); } catch (Exception e) { Console.WriteLine(e.Message); return(null); } }
/// <summary> /// Encrypt a file with AES using only a password /// </summary> /// <param name="password"></param> /// <param name="data"></param> /// <returns>encryptedFile</returns> public byte[] PackFile(string password, byte[] data) { try { var passwordBytes = Encoding.UTF8.GetBytes(password); return(UlteriusAes.EncryptFile(data, passwordBytes)); } catch (Exception e) { Console.WriteLine($"Console unable to pack file: {e.Message}"); return(null); } }