当前位置:编程学习 > 网站相关 >>

DES的加密类(创建文件夹,隐藏文件夹)


using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Security.Cryptography; // Marshal.Free ..

namespace enote902.Common
{
    class DESEncrypt
    {
        private const string key = "888888";
        private const  string IV = "888888*";

        /// <summary>
        /// 加密文件名(包含左右)
        /// </summary>
        /// <param name="caseId">案件号码</param>
        /// <param name="obj">问话对象</param>
        /// <param name="times">第几次</param>
        /// <returns>文件名加密(包含左右)</returns>
        public string[] Encryptor(string caseId, string obj, int times)
        {
            try
            {
                string temp = caseId + "//" + obj + "//" + times.ToString();
                string DESName = Encrypt(temp);
                //找到当前路径。
                string fileD = System.AppDomain.CurrentDomain.BaseDirectory + "Video\\";//debug文件下面
                if (!Directory.Exists(fileD))
                {//如果不存在就创建file文件夹
                    Directory.CreateDirectory(fileD);//创建该文件夹

                }
                DirectoryInfo TheFolder = new DirectoryInfo(fileD);//公开用于创建、移动和枚举目录和子目录的实例方法。无法继承此类。

                //判读是否是隐藏文件夹
                if (TheFolder.Attributes.ToString().IndexOf("Hidden") == -1)
                {
                    File.SetAttributes(fileD, FileAttributes.Hidden);
                }

                string onefile = DESName + "1.avi";
                string twofile = DESName + "2.avi";


                string onepath = fileD + DESName + "1.avi";//完整文件路径
                string twopath = fileD + DESName + "2.avi";//完整文件路径
                ////若存在文件。则修改对应的文件名称
                //while (File.Exists(aa) || File.Exists(bb))
                //{
                //}
                if (!File.Exists(onepath) && !File.Exists(twopath))//检测的是文件全路径
                {
                    string[] result = { onefile, twofile };//存储的是文件名称
                    return result;
                }
                else { return null; }
            }
            catch
            {
                return null;
                throw new NotSupportedException("注意,当前文件无法保存!");

            }

        }

        /// <summary>
        /// 得到文件名(包含左右)
        /// </summary>
        /// <param name="caseId">案件号码</param>
        /// <param name="obj">问话对象</param>
        /// <param name="times">第几次</param>
        /// <returns>文件名加密(包含左右)</returns>
        public string[] DEncryptor(string caseId, string obj, int times)
        {
            try
            {
                string temp = caseId + "//" + obj + "//" + times.ToString();
                string DESName = Encrypt(temp);
                //找到当前路径。
                string fileD = System.AppDomain.CurrentDomain.BaseDirectory ;//debug文件下面
                string filePathA = fileD + DESName + "1.avi";//完整文件路径
                string filePathB = fileD + DESName + "2.avi";//完整文件路径

补充:综合编程 , 安全编程 ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,