日期:2014-05-17  浏览次数:21046 次

加密解密读流问题
我用DEC进行文件加密解密,下面是加密解密的方法(加密略)
/// <param name="inFileName">待加密文件的路径</param>
  /// <param name="outFileName">待加密后文件的输出路径</param>

  public void Encrypt(string inFileName, string outFileName)
/// <param name="inFileName">待解密文件的路径</param>
  /// <param name="outFileName">待解密后文件的输出路径</param>
  public void Decrypt(string inFileName, string outFileName)
  {
  try
  {
  FileStream fin = new FileStream(inFileName, FileMode.Open, FileAccess.Read);
  FileStream fout = new FileStream(outFileName, FileMode.OpenOrCreate, FileAccess.Write);
  fout.SetLength(0);

  byte[] bin = new byte[100];
  long rdlen = 0;
  long totlen = fin.Length;
  int len;
  mydes.Key = GetLegalKey();
  mydes.IV = GetLegalIV();
  ICryptoTransform encrypto = mydes.CreateDecryptor();
  CryptoStream cs = new CryptoStream(fout, encrypto, CryptoStreamMode.Write);
  while (rdlen < totlen)
  {
  len = fin.Read(bin, 0, 100);
  cs.Write(bin, 0, len);
  rdlen = rdlen + len;
  }
  cs.Close();
  fout.Close();
  fin.Close();

  }
解密后会保存一个文件,然后我用progress打开解密后的PPT。可是我不想创建解密后PPT文件,而是直接去打开。那该怎么办呢。我这里有dso操作ppt方法,求神人帮助

------解决方案--------------------
那你得先确认ppt是否支持内存加载呢
------解决方案--------------------
C# code
#region ========加密======== 
 
        /// <summary>
        /// 加密
        /// </summary>
        /// <param name="Text"></param>
        /// <returns></returns>
        public static string Encrypt(string Text) 
        {
            return Encrypt(Text,"litianping");
        }
        /// <summary> 
        /// 加密数据 
        /// </summary> 
        /// <param name="Text"></param> 
        /// <param name="sKey"></param> 
        /// <returns></returns> 
        public static string Encrypt(string Text,string sKey) 
        { 
            DESCryptoServiceProvider des = new DESCryptoServiceProvider(); 
            byte[] inputByteArray; 
            inputByteArray=Encoding.Default.GetBytes(Text); 
            des.Key = ASCIIEncoding.ASCII.GetBytes(System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5").Substring(0, 8)); 
            des.IV = ASCIIEncoding.ASCII.GetBytes(System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5").Substring(0, 8)); 
            System.IO.MemoryStream ms=new System.IO.MemoryStream(); 
            CryptoStream cs=new CryptoStream(ms,des.CreateEncryptor(),CryptoStreamMode.Write); 
            cs.Write(inputByteArray,0,inputByteArray.Length); 
            cs.FlushFinalBlock(); 
            StringBuilder ret=new StringBuilder(); 
            foreach( byte b in ms.ToArray()) 
            { 
                ret.AppendFormat("{0:X2}",b); 
            } 
            return ret.ToString(); 
        }
        /// <summary> 
        /// 加密数据 
        /// </summary> 
        /// <param name="Text"></param> 
        /// <param name="sKey"></param> 
        /// <returns></returns> 
        public static string Enc