public static bool DESDecryptFile(string sInputFilename, string sOutputFilename, string sKey) { try { DESCryptoServiceProvider DES = new DESCryptoServiceProvider(); //A 64 bit key and IV is required for this provider. //Set secret key For DES algorithm. DES.Key = ASCIIEncoding.ASCII.GetBytes(sKey); //Set initialization vector. DES.IV = ASCIIEncoding.ASCII.GetBytes(sKey); //Create a file stream to read the encrypted file back. FileStream fsread = new FileStream(sInputFilename, FileMode.Open, FileAccess.Read); //Create a DES decryptor from the DES instance. ICryptoTransform desdecrypt = DES.CreateDecryptor(); //Create crypto stream set to read and do a //DES decryption transform on incoming bytes. CryptoStream cryptostreamDecr = new CryptoStream(fsread, desdecrypt, CryptoStreamMode.Read); //Print the contents of the decrypted file. StreamWriter fsDecrypted = new StreamWriter(sOutputFilename); fsDecrypted.Write(new StreamReader(cryptostreamDecr).ReadToEnd()); fsDecrypted.Flush(); fsDecrypted.Close(); return(true); } catch (Exception ex) { LLogging.WriteLog(ex.TargetSite.Name, LLogging.LogType.ERR, ex); LMessage.ShowMessage("Giải mã không thành công", LMessage.MessageBoxType.Warning); return(false); } }
public static bool DESEncryptFile(string sInputFilename, string sOutputFilename, string sKey) { try { FileStream fsInput = new FileStream(sInputFilename, FileMode.Open, FileAccess.Read); FileStream fsEncrypted = new FileStream(sOutputFilename, FileMode.Create, FileAccess.Write); DESCryptoServiceProvider DES = new DESCryptoServiceProvider(); DES.Key = ASCIIEncoding.ASCII.GetBytes(sKey); DES.IV = ASCIIEncoding.ASCII.GetBytes(sKey); ICryptoTransform desencrypt = DES.CreateEncryptor(); CryptoStream cryptostream = new CryptoStream(fsEncrypted, desencrypt, CryptoStreamMode.Write); byte[] bytearrayinput = new byte[fsInput.Length]; fsInput.Read(bytearrayinput, 0, bytearrayinput.Length); cryptostream.Write(bytearrayinput, 0, bytearrayinput.Length); cryptostream.Close(); fsInput.Close(); fsEncrypted.Close(); return(true); } catch (Exception ex) { LLogging.WriteLog(ex.TargetSite.Name, LLogging.LogType.ERR, ex); LMessage.ShowMessage("Mã hóa không thành công", LMessage.MessageBoxType.Warning); return(false); } }
/// <summary> /// Tạo bảng chứa tham số /// <para>True: Tạo thành công</para> /// <para>False: Tạo không thành công</para> /// </summary> /// <param name="dt">Bảng chứa tham số</param> /// <returns></returns> public static bool MakeParameterTable(ref DataTable dt) { bool bresult = false; try { if (dt == null) { dt = new DataTable("UDTT_INPUT_PARAMETERS"); dt.Columns.Add("PARAM_NAME", typeof(string)); dt.Columns.Add("PARAM_TYPE", typeof(string)); dt.Columns.Add("PARAM_VALUE", typeof(string)); } bresult = true; } catch (Exception ex) { bresult = false; LLogging.WriteLog(System.Reflection.MethodInfo.GetCurrentMethod().ToString(), LLogging.LogType.ERR, ex); } return(bresult); }
/// /// Merges the Docs and renders the destinationFile /// public static void MergePdfDocs(List <string> listFileExport, string mergeFileExport) { //Step 1: Create a Docuement-Object Document document = new Document(); try { //Step 2: we create a writer that listens to the document PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(mergeFileExport, FileMode.Create)); //Step 3: Open the document document.Open(); PdfContentByte cb = writer.DirectContent; PdfImportedPage page; int n = 0; int rotation = 0; //Loops for each file that has been listed foreach (string filename in listFileExport) { //The current file path string filePath = filename; // we create a reader for the document PdfReader reader = new PdfReader(filePath); //Gets the number of pages to process n = reader.NumberOfPages; int i = 0; while (i < n) { i++; document.SetPageSize(reader.GetPageSizeWithRotation(1)); document.NewPage(); //Insert to Destination on the first page if (i == 1) { Chunk fileRef = new Chunk(" "); fileRef.SetLocalDestination(filename); document.Add(fileRef); } page = writer.GetImportedPage(reader, i); rotation = reader.GetPageRotation(i); if (rotation == 90 || rotation == 270) { cb.AddTemplate(page, 0, -1f, 1f, 0, 0, reader.GetPageSizeWithRotation(i).Height); } else { cb.AddTemplate(page, 1f, 0, 0, 1f, 0, 0); } } } } catch (Exception ex) { LLogging.WriteLog(ex.TargetSite.Name, LLogging.LogType.ERR, ex); throw ex; } finally { document.Close(); GC.Collect(); } }
/// <summary> /// Hàm chuyển dữ liệu binary sang một file /// </summary> /// <param name="streamImage">Dữ liệu binary</param> /// <param name="imagePath">Đường dẫn tuyệt đối lưu trữ file</param> /// <returns>True >> thành công, False >> Không thành công</returns> public static bool WriteAbsFileFromStreamData(Stream streamFile, string filePath) { bool result = true; try { if (streamFile.Length == 0) { return(false); } // Tạo các folder trong đường dẫn tuyệt đối của file if (true) { // convert / to \\ string absFilePath = filePath.Replace("/", "\\"); List <string> listFileFolderItem = absFilePath.SplitByDelimiter("\\").ToList(); listFileFolderItem.RemoveAt(listFileFolderItem.Count - 1); string path = ""; LLogging.WriteLog(System.Reflection.MethodInfo.GetCurrentMethod().ToString(), LLogging.LogType.SYS, "WriteAbsFileFromStreamData filePath: " + filePath); foreach (string item in listFileFolderItem) { path += item + "\\"; LLogging.WriteLog(System.Reflection.MethodInfo.GetCurrentMethod().ToString(), LLogging.LogType.SYS, "WriteAbsFileFromStreamData path: " + path); if (!Directory.Exists(path)) { LLogging.WriteLog(System.Reflection.MethodInfo.GetCurrentMethod().ToString(), LLogging.LogType.SYS, "WriteAbsFileFromStreamData CreateDirectory: " + path); //Directory.CreateDirectory(path); try { DirectoryInfo dirInfo = Directory.CreateDirectory(path); LLogging.WriteLog(System.Reflection.MethodInfo.GetCurrentMethod().ToString(), LLogging.LogType.SYS, "WriteAbsFileFromStreamData CreateDirectory result: " + dirInfo.ToString()); } catch (System.Exception ex) { LLogging.WriteLog(System.Reflection.MethodInfo.GetCurrentMethod().ToString(), LLogging.LogType.SYS, "WriteAbsFileFromStreamData CreateDirectory result failed: " + ex); return(false); } } } } // Create a FileStream object to write a stream to a file using (FileStream fileStream = System.IO.File.Create(filePath, (int)streamFile.Length)) { // Fill the bytes[] array with the stream data byte[] bytesInStream = new byte[streamFile.Length]; streamFile.Read(bytesInStream, 0, (int)bytesInStream.Length); // Use FileStream object to write to the specified file fileStream.Write(bytesInStream, 0, bytesInStream.Length); } streamFile.Close(); return(result); } catch (Exception ex) { result = false; LLogging.WriteLog(ex.TargetSite.Name, LLogging.LogType.ERR, ex); } return(result); }
public static bool AddParameterList(ref DataTable dt , string p1 = null , string p2 = null , string p3 = null , string p4 = null , string p5 = null , string p6 = null , string p7 = null , string p8 = null , string p9 = null , string p10 = null , string p11 = null , string p12 = null , string p13 = null , string p14 = null , string p15 = null , string p16 = null , string p17 = null , string p18 = null , string p19 = null , string p20 = null , string p21 = null , string p22 = null , string p23 = null , string p24 = null , string p25 = null , string p26 = null , string p27 = null , string p28 = null , string p29 = null , string p30 = null , string p31 = null , string p32 = null , string p33 = null , string p34 = null , string p35 = null , string p36 = null , string p37 = null , string p38 = null , string p39 = null , string p40 = null , string p41 = null , string p42 = null , string p43 = null , string p44 = null , string p45 = null , string p46 = null , string p47 = null , string p48 = null , string p49 = null , string p50 = null) { bool bresult = false; try { DataRow dr; if (dt == null) { MakeParameterListTable(ref dt); } dr = dt.NewRow(); if (p1 != null) { dr["P1"] = p1; } if (p2 != null) { dr["P2"] = p2; } if (p3 != null) { dr["P3"] = p3; } if (p4 != null) { dr["P4"] = p4; } if (p5 != null) { dr["P5"] = p5; } if (p6 != null) { dr["P6"] = p6; } if (p7 != null) { dr["P7"] = p7; } if (p8 != null) { dr["P8"] = p8; } if (p9 != null) { dr["P9"] = p9; } if (p10 != null) { dr["P10"] = p10; } if (p11 != null) { dr["P11"] = p11; } if (p12 != null) { dr["P12"] = p12; } if (p13 != null) { dr["P13"] = p13; } if (p14 != null) { dr["P14"] = p14; } if (p15 != null) { dr["P15"] = p15; } if (p16 != null) { dr["P16"] = p16; } if (p17 != null) { dr["P17"] = p17; } if (p18 != null) { dr["P18"] = p18; } if (p19 != null) { dr["P19"] = p19; } if (p20 != null) { dr["P20"] = p20; } if (p21 != null) { dr["P21"] = p21; } if (p22 != null) { dr["P22"] = p22; } if (p23 != null) { dr["P23"] = p23; } if (p24 != null) { dr["P24"] = p24; } if (p25 != null) { dr["P25"] = p25; } if (p26 != null) { dr["P26"] = p26; } if (p27 != null) { dr["P27"] = p27; } if (p28 != null) { dr["P28"] = p28; } if (p29 != null) { dr["P29"] = p29; } if (p30 != null) { dr["P30"] = p30; } if (p31 != null) { dr["P31"] = p31; } if (p32 != null) { dr["P32"] = p32; } if (p33 != null) { dr["P33"] = p33; } if (p34 != null) { dr["P34"] = p34; } if (p35 != null) { dr["P35"] = p35; } if (p36 != null) { dr["P36"] = p36; } if (p37 != null) { dr["P37"] = p37; } if (p38 != null) { dr["P38"] = p38; } if (p39 != null) { dr["P39"] = p39; } if (p40 != null) { dr["P40"] = p40; } if (p41 != null) { dr["P41"] = p41; } if (p42 != null) { dr["P42"] = p42; } if (p43 != null) { dr["P43"] = p43; } if (p44 != null) { dr["P44"] = p44; } if (p45 != null) { dr["P45"] = p45; } if (p46 != null) { dr["P46"] = p46; } if (p47 != null) { dr["P47"] = p47; } if (p48 != null) { dr["P48"] = p48; } if (p49 != null) { dr["P49"] = p49; } if (p50 != null) { dr["P50"] = p50; } dt.Rows.Add(dr); dt.AcceptChanges(); bresult = true; } catch (Exception ex) { bresult = false; LLogging.WriteLog(System.Reflection.MethodInfo.GetCurrentMethod().ToString(), LLogging.LogType.ERR, ex); } return(bresult); }
/// <summary> /// Tạo bảng chứa tham số /// <para>True: Tạo thành công</para> /// <para>False: Tạo không thành công</para> /// </summary> /// <param name="dt">Bảng chứa tham số</param> /// <returns></returns> public static bool MakeParameterListTable(ref DataTable dt) { bool bresult = false; try { if (dt == null) { dt = new DataTable("UDTT_INPUT_PARAMETERS_LIST"); dt.Columns.Add("P1", typeof(string)); dt.Columns.Add("P2", typeof(string)); dt.Columns.Add("P3", typeof(string)); dt.Columns.Add("P4", typeof(string)); dt.Columns.Add("P5", typeof(string)); dt.Columns.Add("P6", typeof(string)); dt.Columns.Add("P7", typeof(string)); dt.Columns.Add("P8", typeof(string)); dt.Columns.Add("P9", typeof(string)); dt.Columns.Add("P10", typeof(string)); dt.Columns.Add("P11", typeof(string)); dt.Columns.Add("P12", typeof(string)); dt.Columns.Add("P13", typeof(string)); dt.Columns.Add("P14", typeof(string)); dt.Columns.Add("P15", typeof(string)); dt.Columns.Add("P16", typeof(string)); dt.Columns.Add("P17", typeof(string)); dt.Columns.Add("P18", typeof(string)); dt.Columns.Add("P19", typeof(string)); dt.Columns.Add("P20", typeof(string)); dt.Columns.Add("P21", typeof(string)); dt.Columns.Add("P22", typeof(string)); dt.Columns.Add("P23", typeof(string)); dt.Columns.Add("P24", typeof(string)); dt.Columns.Add("P25", typeof(string)); dt.Columns.Add("P26", typeof(string)); dt.Columns.Add("P27", typeof(string)); dt.Columns.Add("P28", typeof(string)); dt.Columns.Add("P29", typeof(string)); dt.Columns.Add("P30", typeof(string)); dt.Columns.Add("P31", typeof(string)); dt.Columns.Add("P32", typeof(string)); dt.Columns.Add("P33", typeof(string)); dt.Columns.Add("P34", typeof(string)); dt.Columns.Add("P35", typeof(string)); dt.Columns.Add("P36", typeof(string)); dt.Columns.Add("P37", typeof(string)); dt.Columns.Add("P38", typeof(string)); dt.Columns.Add("P39", typeof(string)); dt.Columns.Add("P40", typeof(string)); dt.Columns.Add("P41", typeof(string)); dt.Columns.Add("P42", typeof(string)); dt.Columns.Add("P43", typeof(string)); dt.Columns.Add("P44", typeof(string)); dt.Columns.Add("P45", typeof(string)); dt.Columns.Add("P46", typeof(string)); dt.Columns.Add("P47", typeof(string)); dt.Columns.Add("P48", typeof(string)); dt.Columns.Add("P49", typeof(string)); dt.Columns.Add("P50", typeof(string)); } bresult = true; } catch (Exception ex) { bresult = false; LLogging.WriteLog(System.Reflection.MethodInfo.GetCurrentMethod().ToString(), LLogging.LogType.ERR, ex); } return(bresult); }