当前位置:网站首页>TXT_ File encryption and compression
TXT_ File encryption and compression
2022-06-13 07:03:00 【AndroidOrCSharp】
WinRar hit tar package
string WinRarDir = GetWinRarDir();
WinrarZip(ClearingFileDir, "p_report", dateTime, batchNo.ToString(), Dir, FileName, WinRarDir, "100000000000306");
/// <summary>
/// collect files
/// </summary>
/// <param name="OutPutDir"> The output path </param>
/// <param name="ZipName"></param>
/// <param name="Date"></param>
/// <param name="BatchNo"></param>
/// <param name="FileDir"></param>
/// <param name="FileName"></param>
/// <param name="WinRarDir"> Compressor directory </param>
/// <param name="seatNo"> Organization code </param>
private void WinrarZip(string OutPutDir, string ZipName, string Date, string BatchNo, string FileDir, string FileName, string WinRarDir, string seatNo)
{
try
{
ProcessStartInfo psi = new ProcessStartInfo(WinRarDir + "\\winrar.exe");
psi.WindowStyle = ProcessWindowStyle.Hidden;
// Source file encryption
log.Info(" The source file format is modified to UTF-8");
SendMsgEdit(" The source file format is modified to UTF-8");
TransformFile(FileDir + "\\" + FileName, FileDir + "\\" + FileName);
log.Info(" Source file encryption ");
SendMsgEdit(" Source file encryption ");
EncryptFile(FileDir + "\\" + FileName, FileDir + "\\" + ZipName + FileName);
log.Info(" New encrypted file added to TAR In bag ");
SendMsgEdit(" New encrypted file added to TAR In bag ");
// New encrypted file / The original file is added to TAR In bag
//psi.Arguments = string.Format("a -df -av- -ep1 -ibck -afzip {0}{1}_{2}_{3}.tar {4}", OutPutDir, ZipName, Date, BatchNo, FileDir + "\\" + FileName);
psi.Arguments = string.Format("a -df -av- -ep1 -ibck -afzip {0}{1}_{2}_{3}_{4}.tar {5}", OutPutDir, ZipName, seatNo, Date, BatchNo, FileDir + "\\" + ZipName + FileName);
Process process = Process.Start(psi);
process.WaitForExit();
//TAR Add package to send package
log.Info(" TAR Add package to send package ");
SendMsgEdit(" TAR Add package to send package ");
psi.Arguments = string.Format("a -av- -ep1 -ibck {0}{1}_{2}_{3}_{4}.tar.gz {5}", OutPutDir, ZipName, seatNo, Date, BatchNo, FileDir + "\\" + ZipName + "_" + seatNo + "_" + Date + "_" + BatchNo + ".tar");
process = Process.Start(psi);
process.WaitForExit();
}
catch (Exception ex)
{
log.Info(string.Format(" Exception occurred in fast money forward file encryption , Abnormal information :{0}",ex.Message));
SendMsgEdit(string.Format(" Exception occurred in fast money forward file encryption , Abnormal information :{0}", ex.Message));
}
}
// obtain winrar The installation path
private string GetWinRarDir()
{
RegistryKey rkey = Registry.CurrentUser;
RegistryKey subKey = rkey.OpenSubKey(@"Software\WinRAR SFX", true);
log.Info(" Compressor installation path :" + subKey.GetValue(subKey.GetValueNames()[0].ToString()).ToString());
SendMsgEdit(" Compressor installation path :" + subKey.GetValue(subKey.GetValueNames()[0].ToString()).ToString());
return subKey.GetValue(subKey.GetValueNames()[0].ToString()).ToString();
}
//txt Change the file to UTF-8
private void TransformFile(string InputFilename, string OutputFilename)
{
FileStream fStream = new FileStream(InputFilename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
StreamReader sReader = new StreamReader(fStream, Encoding.Default);
string strRead = sReader.ReadToEnd();
sReader.Close();
fStream.Close();
fStream = new FileStream(OutputFilename, FileMode.Create, FileAccess.Write);
StreamWriter sWriter = new StreamWriter(fStream, Encoding.UTF8);
sWriter.Write(strRead);
sWriter.Close();
fStream.Close();
}
// Encrypt files
private void EncryptFile(string InputFilename, string OutputFilename)
{
string strKey = IniFile.GetCfgValue("SubSystem,QP", "DESKey");
SendMsgEdit(" Read the fast money key :" + strKey);
EncryptDESFile.EncryptFile(InputFilename, OutputFilename, strKey, Encoding.UTF8, FileContentModify);
}
/// <summary>
/// Add... Before the contents of the document 8 individual 8, Fill in blanks after the contents of the document
/// </summary>
/// <param name="strInput"></param>
/// <returns></returns>
private string FileContentModify(string strInput)
{
string strRead = "88888888" + strInput;
byte[] byteInput = Encoding.UTF8.GetBytes(strRead);
return strRead.PadRight(strRead.Length + (8 - byteInput.Length % 8), ' ');
}
/// <summary>
/// The input content needs to be modified with the specified output file code DES File encryption
/// </summary>
/// <param name="InputFilename"></param>
/// <param name="OutputFilename"></param>
/// <param name="sKey"></param>
/// <param name="EncryptEncode"></param>
/// <param name="FileContent"></param>
public static void EncryptFile(string InputFilename, string OutputFilename, string sKey, Encoding EncryptEncode, FileContentHander FileContent)
{
FileStream FileInput = null;
StreamReader sReader = null;
FileStream FileOutput = null;
CryptoStream cryptoStream = null;
try
{
// Determine the key length
sKey = KeyLengthValid(sKey);
// Determine the encoding method of the input file
Encoding fileEncode = GetType(InputFilename);
// Read in file encoding
FileInput = new FileStream(InputFilename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
sReader = new StreamReader(FileInput, fileEncode);
// Read in the data
string strRead = sReader.ReadToEnd();
if (FileContent != null)
{
strRead = FileContent(strRead);
}
//DES Encrypting device
DESCryptoServiceProvider DES = new DESCryptoServiceProvider();
DES.Mode = CipherMode.ECB;
DES.Padding = PaddingMode.None;
DES.Key = EncryptEncode.GetBytes(sKey);
DES.IV = EncryptEncode.GetBytes(sKey);
ICryptoTransform desEncrypt = DES.CreateEncryptor();
FileOutput = new FileStream(OutputFilename, FileMode.Create, FileAccess.Write);
cryptoStream = new CryptoStream(FileOutput, desEncrypt, CryptoStreamMode.Write);
// Write encrypted data with encrypted stream
byte[] byteOutput = EncryptEncode.GetBytes(strRead);
cryptoStream.Write(byteOutput, 0, byteOutput.Length);
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
finally
{
cryptoStream.Close();
FileOutput.Close();
sReader.Close();
FileInput.Close();
}
}Start console call 7zip Command packaging
// obtain winrar The installation path
private string GetRarDir()
{
RegistryKey rkey = Registry.CurrentUser;
RegistryKey subKey = rkey.OpenSubKey(@"Software\7-Zip", true);
log.Info(" Compressor installation path :" + subKey.GetValue(subKey.GetValueNames()[0].ToString()).ToString());
SendMsgEdit(" Compressor installation path :" + subKey.GetValue(subKey.GetValueNames()[0].ToString()).ToString());
return subKey.GetValue(subKey.GetValueNames()[0].ToString()).ToString();
}
private void SevenZip(string OutPutDir, string ZipName, string Date, string BatchNo, string FileDir, string FileName, string RarDir, string seatNo)
{
try
{
FileInfo fileInfo;
ProcessStartInfo psi = new ProcessStartInfo(RarDir + "\\7z.exe");
psi.WindowStyle = ProcessWindowStyle.Hidden;
// Source file encryption
log.Info(" The source file format is modified to UTF-8");
SendMsgEdit(" The source file format is modified to UTF-8");
TransformFile(FileDir + "\\" + FileName, FileDir + "\\" + FileName);
log.Info(" Source file encryption ");
SendMsgEdit(" Source file encryption ");
EncryptFile(FileDir + "\\" + FileName, FileDir + "\\" + FileName);
log.Info(" New encrypted file added to TAR In bag ");
SendMsgEdit(" New encrypted file added to TAR In bag ");
// start-up CMD txt The file is compressed into tar package
Process process = new Process();
process.StartInfo.FileName = "cmd.exe";
string message = "";
string path = RarDir.Substring(0,1)+":";
string exePath = @"cd "+ RarDir;
string command = string.Format(@"7z a " + OutPutDir + ZipName + "_" + seatNo + "_" + Date + "_" + BatchNo + ".tar" + " " + OutPutDir + FileName);
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardInput = true;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.CreateNoWindow = true;
process.Start();
process.StandardInput.WriteLine(path);
process.StandardInput.WriteLine(exePath);
process.StandardInput.WriteLine(command);
process.StandardInput.WriteLine("exit");
message = process.StandardOutput.ReadToEnd();
command = string.Format(@"7z a " + OutPutDir + ZipName + "_" + seatNo + "_" + Date + "_" + BatchNo + ".tar.gz" + " " + OutPutDir + ZipName + "_" + seatNo + "_" + Date + "_" + BatchNo + ".tar");
// Delete after compression txt file
fileInfo = new FileInfo(OutPutDir + FileName);
fileInfo.Delete();
// Open a new one CMD tar Pack compressed into tar.gz
Process tarGz = new Process();
tarGz.StartInfo.FileName = "cmd.exe";
tarGz.StartInfo.UseShellExecute = false;
tarGz.StartInfo.RedirectStandardInput = true;
tarGz.StartInfo.RedirectStandardOutput = true;
tarGz.StartInfo.RedirectStandardError = true;
tarGz.StartInfo.CreateNoWindow = true;
tarGz.Start();
tarGz.StandardInput.WriteLine(path);
tarGz.StandardInput.WriteLine(exePath);
tarGz.StandardInput.WriteLine(command);
tarGz.StandardInput.WriteLine("exit");
message = tarGz.StandardOutput.ReadToEnd();
// Delete after compression tar file
fileInfo = new FileInfo(OutPutDir + ZipName + "_" + seatNo + "_" + Date + "_" + BatchNo + ".tar");
fileInfo.Delete();
}
catch (Exception ex)
{
log.Info(string.Format(" Exception occurred in fast money forward file encryption , Abnormal information :{0}", ex.Message));
SendMsgEdit(string.Format(" Exception occurred in fast money forward file encryption , Abnormal information :{0}", ex.Message));
}
}winrar command :
psi.Arguments = string.Format("a -av- -ep1 -afzip {0}.rar {0}", floderPath);// Compress zip Keep the original file
psi.Arguments = string.Format("a -av- -ep1 -afrar {0}.rar {0}", floderPath);// Compress rar Keep the original file
psi.Arguments = string.Format("m -df- -av- -ep1 -afzip {0}.rar {0}", floderPath); // Compress zip Delete the original file
psi.Arguments = string.Format("m -df- -av- -ep1 -afrar {0}.rar {0}", floderPath);// Compress rar Delete the original file
边栏推荐
- Periodontitis investigation (ongoing)
- Is it safe to open an account online in Hangzhou?
- As the new trend of blind box e-commerce, how can the platform use blind box play to drain at low cost?
- Tidb index optimization
- [weak transient signal detection] matlab simulation of SVM detection method for weak transient signal under chaotic background
- Reflection of C # Foundation
- 牙周炎问题调研(持续进行中)
- 杭州证券开户是安全的吗?
- 【微弱瞬态信号检测】混沌背景下微弱瞬态信号的SVM检测方法的matlab仿真
- Detailed description of drawing ridge plot, overlapping densities of overlapping kernel density estimation curve, facetgrid object and function sns Kdeplot, function facetgrid map
猜你喜欢

FSM状态机

WWDC2022最大的亮点: MetalFX

Common method of props changing value V-model sync

Eureka server multi node deployment

Do you want to carry out rapid steel mesh design and ensure the quality of steel mesh? Look here

Application of DS18B20 temperature sensor based on FPGA

2022-06-12:在N*N的正方形棋盘中,有N*N个棋子,那么每个格子正好可以拥有一个棋子。 但是现在有些棋子聚集到一个格子上了,比如: 2 0 3 0 1 0 3 0 0 如上的二维数组代表,一

Gold jewelry enterprise operation mode, beautiful tiantians business solution

YOLOv5解析 | 参数与性能指标

RT-Thread 模拟器 simulator LVGL控件:button 按钮样式
随机推荐
Xuanwu cloud technology passed the listing hearing: the performance fluctuated significantly, and chenyonghui and other three were the controlling shareholders
Differences between SQL and NoSQL of mongodb series
Periodontitis investigation (ongoing)
Tidb index optimization
Brief introduction to basic usage of echart
Can flush open a stock account? Is it safe?
Tikv key performance parameters and optimization
Tidb statistics
105. constructing binary trees from preorder and inorder traversal sequences
Try to use renderdoc to view the shader code of UE
RT-Thread 模拟器 simulator LVGL控件:button 按钮样式
TiDB Lightning
Common method of props changing value V-model sync
2022-06-12:在N*N的正方形棋盘中,有N*N个棋子,那么每个格子正好可以拥有一个棋子。 但是现在有些棋子聚集到一个格子上了,比如: 2 0 3 0 1 0 3 0 0 如上的二维数组代表,一
What does my financial product mean in clearing?
It's called the next generation monitoring system. Let's see how awesome it is
基于FPGA的ds18b20温度传感器使用
Vsys of Isis (virtual system)
【騰訊阿裏最全面試題集錦】(四面:3輪技術+1輪HR)
考研英语