public void CryptFile(string SourcePath, string DestinationPath, List<ulong> KeyList) { FileInfo file = new FileInfo(SourcePath); FileStream fs = new FileStream(SourcePath, FileMode.Open, FileAccess.Read); DES des = new DES(); ulong bufLong = 0; byte[] buffer = new byte[file.Length]; fs.Read(buffer, 0, (int)file.Length); fs.Dispose(); for (long i = 0; i < file.Length - file.Length % Const.BlockSizeForFile; i += Const.BlockSizeForFile) { ulong temp = 0; for (byte j = 0; j < Const.BlockSizeForFile; j++) { temp |= (ulong)buffer[i + j]; bufLong = temp; temp <<= Const.BlockSizeForFile; } bufLong = des.Crypt(bufLong, KeyList); for (short j = 7; j >= 0; j--) { buffer[i + j] = (byte)(bufLong & Const.Mask8Bit); bufLong >>= Const.BlockSizeForFile; } } FileStream fscrypt = new FileStream(DestinationPath, FileMode.Create, FileAccess.ReadWrite); fscrypt.Write(buffer, 0, (int)file.Length); fscrypt.Dispose(); } |