DES類
?#region DES文件
public static void LogsAdd(string str)
{
}
? ? ? ? /// <summary>
? ? ? ? /// 判斷是否十進制格式字符串
? ? ? ? /// </summary>
? ? ? ? /// <param name="str">字符串</param>
? ? ? ? /// <returns>true 是? false 不是</returns>
? ? ? ? public static bool IsDecimal(string str)
? ? ? ? {
? ? ? ? ? ? if (string.IsNullOrEmpty(str))
? ? ? ? ? ? ? ? return false;
? ? ? ? ? ? const string PATTERN = @"([^0-9]|\s+?)+";
? ? ? ? ? ? if (System.Text.RegularExpressions.Regex.IsMatch(str, PATTERN))
? ? ? ? ? ? {
? ? ? ? ? ? ? ? LogsAdd("輸入錯誤:有非法字符串!");
? ? ? ? ? ? ? ? return false;
? ? ? ? ? ? }
? ? ? ? ? ? return true;
? ? ? ? }
? ? ? ? /// <summary>
? ? ? ? /// 十進制字符串轉(zhuǎn)字節(jié)數(shù)組
? ? ? ? /// </summary>
? ? ? ? /// <param name="str">字符串</param>
? ? ? ? /// <returns></returns>
? ? ? ? public static byte[] DecimalStringToByte(string str)
? ? ? ? {
? ? ? ? ? ? if (string.IsNullOrEmpty(str))
? ? ? ? ? ? {
? ? ? ? ? ? ? ? LogsAdd("輸入錯誤:輸入字符串為空!");
? ? ? ? ? ? ? ? return null;
? ? ? ? ? ? }
? ? ? ? ? ? if (IsDecimal(str))
? ? ? ? ? ? {
? ? ? ? ? ? ? ? int splitBase = 3;
? ? ? ? ? ? ? ? if (str.Length % splitBase == 0)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? int len = str.Length / splitBase;
? ? ? ? ? ? ? ? ? ? byte[] arr_des = new byte[len];
? ? ? ? ? ? ? ? ? ? for (int i = 0; i < len; i++)
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? int a = Convert.ToInt32(str.Substring(i * splitBase, splitBase));
? ? ? ? ? ? ? ? ? ? ? ? if (a > 255)
? ? ? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? ? ? LogsAdd("輸入錯誤:輸入值大于255!");
? ? ? ? ? ? ? ? ? ? ? ? ? ? return null;
? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? arr_des[i] = Convert.ToByte(a);
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? LogsAdd("十進制字符串轉(zhuǎn)字節(jié)數(shù)組轉(zhuǎn)換成功。");
? ? ? ? ? ? ? ? ? ? return arr_des;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? else
? ? ? ? ? ? ? ? ? ? LogsAdd("輸入錯誤:長度不對!");
? ? ? ? ? ? }
? ? ? ? ? ? return null;
? ? ? ? }
? ? ? ? /// <summary>
? ? ? ? /// 字節(jié)數(shù)組轉(zhuǎn)十進制字符串
? ? ? ? /// </summary>
? ? ? ? /// <param name="Byte"></param>
? ? ? ? /// <param name="interval"></param>
? ? ? ? /// <returns></returns>
? ? ? ? public static string ByteToDecimalString(byte[] Byte, string interval = "")
? ? ? ? {
? ? ? ? ? ? StringBuilder result = new StringBuilder();
? ? ? ? ? ? if (Byte != null)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? foreach (byte b in Byte)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? result.Append(b.ToString("D3") + interval);
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? LogsAdd("字節(jié)轉(zhuǎn)十進制字符串轉(zhuǎn)換成功。");
? ? ? ? ? ? ? ? return result.ToString();
? ? ? ? ? ? }
? ? ? ? ? ? LogsAdd("字節(jié)為空!");
? ? ? ? ? ? return null;
? ? ? ? }
? ? ? ? /// <summary>
? ? ? ? /// DES字符串加密。CBC模式
? ? ? ? /// </summary>
? ? ? ? /// <param name="targetValue">加密字符串</param>
? ? ? ? /// <param name="key">秘鑰只能是8位(不支持中文)</param>
? ? ? ? /// <param name="iv">向量要大于或等于8位</param>
? ? ? ? /// <param name="encoding">加密字符串編碼</param>
? ? ? ? /// <returns>輸出加密字符,字符串類型(十進制值輸出)</returns>
? ? ? ? public static string DesCBCEncrypt(string targetValue, string key, string iv, string encoding = "UTF-8")
? ? ? ? {
? ? ? ? ? ? string str_des = null;
? ? ? ? ? ? if (key.Length != 8 | iv.Length < 8)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? LogsAdd("DES失?。好艽a長度不是8位或向量小于8位!");
? ? ? ? ? ? ? ? return str_des;
? ? ? ? ? ? }
? ? ? ? ? ? if (string.IsNullOrEmpty(targetValue))
? ? ? ? ? ? {
? ? ? ? ? ? ? ? LogsAdd("DES失?。杭用茏址疄榭?!");
? ? ? ? ? ? ? ? return str_des;
? ? ? ? ? ? }
? ? ? ? ? ? try
? ? ? ? ? ? {
? ? ? ? ? ? ? ? byte[] arr_key = Encoding.UTF8.GetBytes(key.Substring(0, 8));
? ? ? ? ? ? ? ? byte[] arr_iv = Encoding.UTF8.GetBytes(iv);//.Substring(0, 4)
? ? ? ? ? ? ? ? byte[] arr_str = Encoding.GetEncoding(encoding).GetBytes(targetValue);
? ? ? ? ? ? ? ? DESCryptoServiceProvider des = new DESCryptoServiceProvider();
? ? ? ? ? ? ? ? MemoryStream mStream = new MemoryStream();//實例化內(nèi)存流對象
? ? ? ? ? ? ? ? des.Mode = CipherMode.CBC;//指定要用于加密的塊密碼模式。
? ? ? ? ? ? ? ? using (CryptoStream cs = new CryptoStream(mStream, des.CreateEncryptor(arr_key, arr_iv), CryptoStreamMode.Write))//將數(shù)據(jù)流鏈接到加密轉(zhuǎn)換的流。? ? ? ? ? ?
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? cs.Write(arr_str, 0, arr_str.Length);
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? str_des = ByteToDecimalString(mStream.ToArray());
? ? ? ? ? ? ? ? LogsAdd("DES成功!");
? ? ? ? ? ? ? ? return str_des;
? ? ? ? ? ? }
? ? ? ? ? ? catch (Exception ex)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? LogsAdd("DES失?。?#34; + ex.Message);
? ? ? ? ? ? ? ? return str_des;
? ? ? ? ? ? }
? ? ? ? }
? ? ? ? /// <summary>
? ? ? ? /// DES字符串解密。CBC模式
? ? ? ? /// </summary>
? ? ? ? /// <param name="targetValue">加密字符串</param>
? ? ? ? /// <param name="key">秘鑰只能是8位(不支持中文)</param>
? ? ? ? /// <param name="iv">向量要大于或等于8位</param>
? ? ? ? /// <param name="encoding">加密字符串編碼</param>
? ? ? ? /// <returns>輸出加密字符,字符串類型(十進制值輸出)</returns>
? ? ? ? public static string DesCBCDecrypt(string targetValue, string key, string iv, string encoding = "UTF-8")
? ? ? ? {
? ? ? ? ? ? string str_des = null;
? ? ? ? ? ? if (key.Length != 8 | iv.Length < 8)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? LogsAdd("DES失敗:密碼長度不是8位或向量小于8位!");
? ? ? ? ? ? ? ? return str_des;
? ? ? ? ? ? }
? ? ? ? ? ? if (string.IsNullOrEmpty(targetValue))
? ? ? ? ? ? {
? ? ? ? ? ? ? ? LogsAdd("DES失敗:加密字符串為空!");
? ? ? ? ? ? ? ? return str_des;
? ? ? ? ? ? }
? ? ? ? ? ? try
? ? ? ? ? ? {
? ? ? ? ? ? ? ? //定義字節(jié)數(shù)組用來存放密鑰 GetBytes方法用于將字符串中所有字節(jié)編碼為一個字節(jié)序列
? ? ? ? ? ? ? ? byte[] arr_key = Encoding.UTF8.GetBytes(key.Substring(0, 8));
? ? ? ? ? ? ? ? byte[] arr_iv = Encoding.UTF8.GetBytes(iv);//.Substring(0, 4)
? ? ? ? ? ? ? ? byte[] arr_des = DecimalStringToByte(targetValue);
? ? ? ? ? ? ? ? MemoryStream ms = new MemoryStream();
? ? ? ? ? ? ? ? //方法定義加密對象
? ? ? ? ? ? ? ? DESCryptoServiceProvider des = new DESCryptoServiceProvider();
? ? ? ? ? ? ? ? des.Mode = CipherMode.CBC;
? ? ? ? ? ? ? ? using (CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(arr_key, arr_iv), CryptoStreamMode.Write))
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? cs.Write(arr_des, 0, arr_des.Length);
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? str_des = Encoding.GetEncoding(encoding).GetString(ms.ToArray());
? ? ? ? ? ? ? ? LogsAdd("DES成功!");
? ? ? ? ? ? ? ? return str_des;
? ? ? ? ? ? }
? ? ? ? ? ? catch (Exception ex)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? LogsAdd("DES失?。?#34; + ex.Message);
? ? ? ? ? ? ? ? return str_des;
? ? ? ? ? ? }
? ? ? ? }
? ? ? ? /// <summary>
? ? ? ? /// DES字符串加密。ECB模式
? ? ? ? /// </summary>
? ? ? ? /// <param name="targetValue">加密字符串</param>
? ? ? ? /// <param name="key">秘鑰只能是8位(不支持中文)</param>
? ? ? ? /// <param name="iv">沒有用</param>
? ? ? ? /// <param name="encoding">加密字符串編碼</param>
? ? ? ? /// <returns>輸出加密字符,字符串類型(Base64)</returns>
? ? ? ? public static string DesEBCEncrypt(string targetValue, string key, string iv, string encoding = "UTF-8")
? ? ? ? {
? ? ? ? ? ? string str_des = null;
? ? ? ? ? ? if (key.Length != 8)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? LogsAdd("DES失敗:密碼長度不是8位!");
? ? ? ? ? ? ? ? return str_des;
? ? ? ? ? ? }
? ? ? ? ? ? if (string.IsNullOrEmpty(targetValue))
? ? ? ? ? ? {
? ? ? ? ? ? ? ? LogsAdd("DES失敗:加密字符串為空!");
? ? ? ? ? ? ? ? return str_des;
? ? ? ? ? ? }
? ? ? ? ? ? try
? ? ? ? ? ? {
? ? ? ? ? ? ? ? byte[] arr_key = Encoding.UTF8.GetBytes(key);
? ? ? ? ? ? ? ? byte[] arr_iv = Encoding.UTF8.GetBytes(iv.Substring(0, 8));//如果字符串長度大于8個,截取前面8個字符串
? ? ? ? ? ? ? ? byte[] arr_str = Encoding.GetEncoding(encoding).GetBytes(targetValue);
? ? ? ? ? ? ? ? DESCryptoServiceProvider des = new DESCryptoServiceProvider();
? ? ? ? ? ? ? ? MemoryStream mStream = new MemoryStream();//實例化內(nèi)存流對象
? ? ? ? ? ? ? ? des.Mode = CipherMode.ECB;//指定要用于加密的塊密碼模式。
? ? ? ? ? ? ? ? using (CryptoStream cs = new CryptoStream(mStream, des.CreateEncryptor(arr_key, arr_iv), CryptoStreamMode.Write))//將數(shù)據(jù)流鏈接到加密轉(zhuǎn)換的流。
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? cs.Write(arr_str, 0, arr_str.Length);
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? str_des = Convert.ToBase64String(mStream.ToArray());
? ? ? ? ? ? ? ? LogsAdd("DES成功!");
? ? ? ? ? ? ? ? return str_des;
? ? ? ? ? ? }
? ? ? ? ? ? catch (Exception ex)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? LogsAdd("DES失?。?#34; + ex.Message);
? ? ? ? ? ? ? ? return str_des;
? ? ? ? ? ? }
? ? ? ? }
? ? ? ? /// <summary>
? ? ? ? /// DES字符串解密。ECB模式
? ? ? ? /// </summary>
? ? ? ? /// <param name="targetValue">加密字符串</param>
? ? ? ? /// <param name="key">秘鑰只能是8位(不支持中文)</param>
? ? ? ? /// <param name="iv">沒有用</param>
? ? ? ? /// <param name="encoding">加密字符串編碼</param>
? ? ? ? /// <returns>輸出加密字符,字符串類型(Base64)</returns>
? ? ? ? public static string DesEBCDecrypt(string targetValue, string key, string iv, string encoding = "UTF-8")
? ? ? ? {
? ? ? ? ? ? string str_des = null;
? ? ? ? ? ? if (key.Length != 8)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? LogsAdd("DES失?。好艽a長度不是8位!");
? ? ? ? ? ? ? ? return str_des;
? ? ? ? ? ? }
? ? ? ? ? ? if (string.IsNullOrEmpty(targetValue))
? ? ? ? ? ? {
? ? ? ? ? ? ? ? LogsAdd("DES失?。杭用茏址疄榭?!");
? ? ? ? ? ? ? ? return str_des;
? ? ? ? ? ? }
? ? ? ? ? ? try
? ? ? ? ? ? {
? ? ? ? ? ? ? ? //定義字節(jié)數(shù)組用來存放密鑰 GetBytes方法用于將字符串中所有字節(jié)編碼為一個字節(jié)序列
? ? ? ? ? ? ? ? byte[] arr_key = Encoding.UTF8.GetBytes(key);//.Substring(0, 8)
? ? ? ? ? ? ? ? byte[] arr_iv = Encoding.UTF8.GetBytes(iv);//.Substring(0, 8)
? ? ? ? ? ? ? ? byte[] arr_des = Convert.FromBase64String(targetValue);
? ? ? ? ? ? ? ? MemoryStream mStream = new MemoryStream();
? ? ? ? ? ? ? ? DESCryptoServiceProvider des = new DESCryptoServiceProvider();
? ? ? ? ? ? ? ? des.Mode = CipherMode.ECB;
? ? ? ? ? ? ? ? using (CryptoStream cs = new CryptoStream(mStream, des.CreateDecryptor(arr_key, arr_iv), CryptoStreamMode.Write))
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? cs.Write(arr_des, 0, arr_des.Length);
? ? ? ? ? ? ? ? ? ? //cs.FlushFinalBlock();
? ? ? ? ? ? ? ? ? ? //cs.Close();
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? str_des = Encoding.GetEncoding(encoding).GetString(mStream.ToArray());
? ? ? ? ? ? ? ? LogsAdd("DES成功!");
? ? ? ? ? ? ? ? return str_des;
? ? ? ? ? ? }
? ? ? ? ? ? catch (Exception ex)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? LogsAdd("DES失敗:" + ex.Message);
? ? ? ? ? ? ? ? return str_des;
? ? ? ? ? ? }
? ? ? ? }
? ? ? ? /// <summary>
? ? ? ? /// DES文件加密。CBC模式
? ? ? ? /// </summary>
? ? ? ? /// <param name="filePath">源文件</param>
? ? ? ? /// <param name="savePath">保存文件</param>
? ? ? ? /// <param name="keyString">秘鑰只能是8位(不支持中文)</param>
? ? ? ? /// <param name="ivString">向量要大于或等于8位</param>
? ? ? ? /// <returns>成功返回1,失敗返回-1</returns>
? ? ? ? public static int DesCBCEncryptFile(string filePath, string savePath, string keyString, string ivString)
? ? ? ? {
? ? ? ? ? ? int i = -1;
? ? ? ? ? ? var des = GetDesCryptoServiceProvider(keyString, ivString);
? ? ? ? ? ? if (des == null)
? ? ? ? ? ? ? ? return i;
? ? ? ? ? ? ICryptoTransform cryptoTransform = des.CreateEncryptor();
? ? ? ? ? ? if (CryptoFileContent(filePath, savePath, cryptoTransform) == 1)
? ? ? ? ? ? ? ? return 1;
? ? ? ? ? ? return i;
? ? ? ? }
? ? ? ? /// <summary>
? ? ? ? /// DES文件解密。CBC模式
? ? ? ? /// </summary>
? ? ? ? /// <param name="filePath">源文件</param>
? ? ? ? /// <param name="savePath">保存文件</param>
? ? ? ? /// <param name="keyString">秘鑰只能是8位(不支持中文)</param>
? ? ? ? /// <param name="ivString">向量要大于或等于8位</param>
? ? ? ? /// <returns>成功返回1,失敗返回-1</returns>
? ? ? ? public static int DesCBCDecryptFile(string filePath, string savePath, string keyString, string ivString)
? ? ? ? {
? ? ? ? ? ? int i = -1;
? ? ? ? ? ? var des = GetDesCryptoServiceProvider(keyString, ivString);
? ? ? ? ? ? if (des == null)
? ? ? ? ? ? ? ? return i;
? ? ? ? ? ? ICryptoTransform cryptoTransform = des.CreateDecryptor();
? ? ? ? ? ? if (CryptoFileContent(filePath, savePath, cryptoTransform) == 1)
? ? ? ? ? ? ? ? return 1;
? ? ? ? ? ? return i;
? ? ? ? }
? ? ? ? /// <summary>
? ? ? ? /// DES獲取加密服務(wù)提供者,SHA一次在截取8位。
? ? ? ? /// </summary>
? ? ? ? /// <param name="keyString">秘鑰只能是8位(不支持中文)</param>
? ? ? ? /// <param name="ivString">向量要大于或等于8位</param>
? ? ? ? /// <returns>成功返回DESCryptoServiceProvider類型,失敗返回null</returns>
? ? ? ? private static DESCryptoServiceProvider GetDesCryptoServiceProvider(string keyStr, string ivStr)
? ? ? ? {
? ? ? ? ? ? if (keyStr.Length != 8 | ivStr.Length != 8)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? LogsAdd("DES失敗:密碼長度不是8位或向量長度不是8位!");
? ? ? ? ? ? ? ? return null;
? ? ? ? ? ? }
? ? ? ? ? ? byte[] keyBytes = Encoding.UTF8.GetBytes(keyStr);
? ? ? ? ? ? SHA1 keysha = new SHA1Managed();//計算指定字節(jié)組指定區(qū)域哈希值
? ? ? ? ? ? byte[] keyhash = keysha.ComputeHash(keyBytes);
? ? ? ? ? ? //加密密鑰數(shù)組
? ? ? ? ? ? byte[] key = new byte[8];
? ? ? ? ? ? for (int i = 0; i < 8; i++)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? key[i] = keyhash[i];
? ? ? ? ? ? }
? ? ? ? ? ? byte[] ivBytes = Encoding.UTF8.GetBytes(ivStr);
? ? ? ? ? ? SHA1 ivsha = new SHA1Managed();//計算指定字節(jié)組指定區(qū)域哈希值
? ? ? ? ? ? byte[] ivhash = ivsha.ComputeHash(keyBytes);
? ? ? ? ? ? //加密密鑰數(shù)組
? ? ? ? ? ? byte[] iv = new byte[8];
? ? ? ? ? ? for (int i = 0; i < 8; i++)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? iv[i] = ivhash[i];
? ? ? ? ? ? }
? ? ? ? ? ? DESCryptoServiceProvider des = new DESCryptoServiceProvider { Key = key, IV = iv };
? ? ? ? ? ? return des;
? ? ? ? }
? ? ? ? /// <summary>
? ? ? ? /// DES或文件內(nèi)容
? ? ? ? /// </summary>
? ? ? ? /// <param name="filePath"></param>
? ? ? ? /// <param name="savePath"></param>
? ? ? ? /// <param name="cryptoTransform"></param>
? ? ? ? /// <returns>成功返回1,失敗返回-1</returns>
? ? ? ? private static int CryptoFileContent(string filePath, string savePath, ICryptoTransform cryptoTransform)
? ? ? ? {
? ? ? ? ? ? int i = -1;
? ? ? ? ? ? if (!File.Exists(filePath))
? ? ? ? ? ? {
? ? ? ? ? ? ? ? LogsAdd("DES失?。褐付ㄎ募?" + filePath + " 找不到.");
? ? ? ? ? ? ? ? return i;
? ? ? ? ? ? }
? ? ? ? ? ? byte[] inputByteArray = null;
? ? ? ? ? ? FileStream fileStream;
? ? ? ? ? ? try
? ? ? ? ? ? {
? ? ? ? ? ? ? ? using (MemoryStream memoryStream = new MemoryStream())
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? using (CryptoStream cryptoStream = new CryptoStream(memoryStream, cryptoTransform, CryptoStreamMode.Write))
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? fileStream = File.OpenRead(filePath);
? ? ? ? ? ? ? ? ? ? ? ? using (BinaryReader binaryReader = new BinaryReader(fileStream))
? ? ? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? ? ? inputByteArray = new byte[fileStream.Length];
? ? ? ? ? ? ? ? ? ? ? ? ? ? binaryReader.Read(inputByteArray, 0, inputByteArray.Length);
? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? cryptoStream.Write(inputByteArray, 0, inputByteArray.Length);
? ? ? ? ? ? ? ? ? ? ? ? cryptoStream.FlushFinalBlock();
? ? ? ? ? ? ? ? ? ? ? ? using (fileStream = File.OpenWrite(savePath))
? ? ? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? ? ? memoryStream.WriteTo(fileStream);
? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? LogsAdd("DES成功!");
? ? ? ? ? ? ? ? return 1;
? ? ? ? ? ? }
? ? ? ? ? ? catch (Exception ex)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? LogsAdd("DES失敗:" + ex.Message);
? ? ? ? ? ? ? ? return i;
? ? ? ? ? ? }
? ? ? ? }
? ? ? ? ///// <summary>
? ? ? ? ///// DES保存文件
? ? ? ? ///// </summary>
? ? ? ? ///// <param name="savePath"></param>
? ? ? ? ///// <param name="memoryStream"></param>
? ? ? ? //private static void SaveFile(string savePath, MemoryStream memoryStream)
? ? ? ? //{
? ? ? ? //? ? using (FileStream fileStream = File.OpenWrite(savePath))
? ? ? ? //? ? {
? ? ? ? //? ? ? ? memoryStream.WriteTo(fileStream);
? ? ? ? //? ? }
? ? ? ? //}
? ? ? ? ///// <summary>
? ? ? ? ///// DES讀取文件內(nèi)容為字節(jié)
? ? ? ? ///// </summary>
? ? ? ? ///// <param name="filePath"></param>
? ? ? ? ///// <returns></returns>
? ? ? ? //private static byte[] ReadFileAsBytes(string filePath)
? ? ? ? //{
? ? ? ? //? ? FileStream fileStream = File.OpenRead(filePath);
? ? ? ? //? ? using (BinaryReader binaryReader = new BinaryReader(fileStream))
? ? ? ? //? ? {
? ? ? ? //? ? ? ? byte[] inputByteArray = new byte[fileStream.Length];
? ? ? ? //? ? ? ? binaryReader.Read(inputByteArray, 0, inputByteArray.Length);
? ? ? ? //? ? ? ? return inputByteArray;
? ? ? ? //? ? }
? ? ? ? //}
? ? ? ? #endregion