示例#1
0
        public static void MakeDecryptor(string path)
        {
            var bytes = File.ReadAllBytes(path);

            try
            {
                bytes = UtilSecurity.EncryptionBytes(bytes, UtilSecurity.MakeEncryptorTransform(Path.GetFileName(path)));
                FileHelper.CreateDirectory(path);
                File.WriteAllBytes(path, bytes);
            }
            catch (Exception)
            {
                throw;
            }
        }
示例#2
0
        public YueGeEncrypt()
        {
            var md5Key = "kEfGhnNmeu4YYuhv";

            var root = SystemConsole.GetInputStr("输入目录:");

            if (Directory.Exists(root))
            {
                var folder = Path.GetFileName(root);
                var files  =
                    Directory.GetFiles(root, "*.*", SearchOption.AllDirectories)
                    .Select(p => p.Replace(root, "").Replace("\\", "/"))
                    .ToList();

                var dirRoot = root.Replace(folder, "");
                files.ForEach((file, i, count) =>
                {
                    var path     = folder + file;
                    var dirName  = Path.GetDirectoryName(path).Replace("\\", "/");
                    var fileName = Path.GetFileName(path);
                    var newPath  = dirName.MD5(md5Key) + "/" + fileName.MD5(md5Key);

                    var outPath = dirRoot + "md5/" + newPath;
                    var p       = ((float)i / count).ToString("P") + "\t" + path;
                    FileHelper.CreateDirectory(outPath);
                    if (extensionList.Contains(Path.GetExtension(path)))
                    {
                        Console.WriteLine("路径编码中..." + p);
                        File.Copy(root + file, outPath, true);
                    }
                    else
                    {
                        Console.WriteLine("路径编码并文件加密中..." + p);
                        File.WriteAllBytes(outPath, UtilSecurity.EncryptionBytes(File.ReadAllBytes(root + file)));
                    }
                });
            }
        }