public static void DeCryptFile(string sourceFileName) { string tempfilename = sourceFileName + ".temp"; AESReader treader = new AESReader(sourceFileName); if (!treader.IsEncrypt) { treader.Dispose(); DLog.LogError("试图解密一个非加密文件或文件无法解密."); return; } byte[] tallbytes = treader.ReadAllBytes(); treader.Dispose(); File.WriteAllBytes(tempfilename, tallbytes); File.Delete(sourceFileName); File.Move(tempfilename, sourceFileName); }
public static void EnCryptFile(string sourceFileName) { string tempfilename = sourceFileName + ".temp"; AESReader tsourcefile = new AESReader(sourceFileName); if (tsourcefile.IsEncrypt) { DLog.LogError("尝试对已经加密的文件进行2次加密.sourceFileName = " + sourceFileName); tsourcefile.Dispose(); return; } byte[] tallbytes = tsourcefile.ReadAllBytes(); tsourcefile.Dispose(); AESWriter twriter = new AESWriter(tempfilename); twriter.WriteBytes(tallbytes); twriter.Close(); File.Delete(sourceFileName); File.Move(tempfilename, sourceFileName); }