为什么相同的过程执行多次,DES加密以后的密文不一致?
rehuo 2018-10-22 03:34:53 public static string DesEncrypt(string sValue, string sKey)
{
string outString = "";
try
{
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
byte[] buffer = Encoding.UTF8.GetBytes(sValue);
des.Padding = PaddingMode.ISO10126;
des.Mode = CipherMode.ECB;
des.Key = Encoding.UTF8.GetBytes(sKey.PadLeft(8, '0').Substring(0, 8));
des.IV = Encoding.UTF8.GetBytes(sKey.PadLeft(8, '0').Substring(0, 8));
MemoryStream ms = new MemoryStream();
using (CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(), CryptoStreamMode.Write))
{
cs.Write(buffer, 0, buffer.Length);
cs.FlushFinalBlock();
cs.Close();
}
byte[] by = ms.ToArray();
foreach (byte item in by)
{
outString += item.ToString("X").PadLeft(2, '0');
}
ms.Dispose();
des.Clear();
}
catch
{
outString = "";
}
return outString;
}
Key="12345678",value="111111",为什么连续执行上面过程多次,每次得到的结果都不一样?