private static Globals.ResultType Decrypt(this FileObject fileObject, string strDecryptedFilename, string strKey) { try { // Create DES Provider DESCryptoServiceProvider DES = new DESCryptoServiceProvider(); DES.Key = ASCIIEncoding.ASCII.GetBytes(strKey); DES.IV = ASCIIEncoding.ASCII.GetBytes(strKey); // Read Encrypted File FileStream stream = new FileStream(fileObject.FilePath, FileMode.Open, FileAccess.Read); ICryptoTransform desdecrypt = DES.CreateDecryptor(); CryptoStream cryptostreamDecr = new CryptoStream(stream, desdecrypt, CryptoStreamMode.Read); // Write Decrypted File StreamWriter fsDecrypted = new StreamWriter(strDecryptedFilename); fsDecrypted.Write(new StreamReader(cryptostreamDecr).ReadToEnd()); fsDecrypted.Flush(); fsDecrypted.Close(); // Refresh File Object fileObject.Refresh(); return(Globals.ResultType.Success); } catch (Exception ex) { // To Be Implemented: Throw Custom Exception... Console.WriteLine(ex.ToString()); return(Globals.ResultType.Failure); } }
private static Globals.ResultType Encrypt(this FileObject fileObject, string strEncryptedFilename, string strKey) { try { // Read File FileStream stream = new FileStream(fileObject.FilePath, FileMode.Open, FileAccess.Read); FileStream streamEncrypted = new FileStream(strEncryptedFilename, FileMode.Create, FileAccess.Write); DESCryptoServiceProvider DES = new DESCryptoServiceProvider(); DES.Key = ASCIIEncoding.ASCII.GetBytes(strKey); DES.IV = ASCIIEncoding.ASCII.GetBytes(strKey); // Create Encryptor ICryptoTransform desencrypt = DES.CreateEncryptor(); CryptoStream cryptostream = new CryptoStream(streamEncrypted, desencrypt, CryptoStreamMode.Write); byte[] bytearrayinput = new byte[stream.Length]; stream.Read(bytearrayinput, 0, bytearrayinput.Length); // Write to File cryptostream.Write(bytearrayinput, 0, bytearrayinput.Length); cryptostream.Close(); stream.Close(); // Refresh File Object fileObject.Refresh(); return(Globals.ResultType.Success); } catch (Exception ex) { // To Be Implemented: Throw Custom Exception... Console.WriteLine(ex.ToString()); return(Globals.ResultType.Failure); } }
private static Globals.ResultType Encrypt(this FileObject fileObject) { try { System.IO.File.Encrypt(fileObject.FilePath); // Refresh File Object fileObject.Refresh(); return(Globals.ResultType.Success); } catch (Exception ex) { // To Be Implemented: Throw Custom Exception... Console.WriteLine(ex.ToString()); return(Globals.ResultType.Failure); } }
private static Globals.ResultType SetAttributes(this FileObject fileObject, System.IO.FileAttributes fileAttributes) { try { // Set File Attributes System.IO.File.SetAttributes(fileObject.FilePath, fileAttributes); // Refresh File Object fileObject.Refresh(); return(Globals.ResultType.Success); } catch (Exception ex) { // To Be Implemented: Throw Custom Exception... Console.WriteLine(ex.ToString()); return(Globals.ResultType.Failure); } }