问题遇到的现象和发生背景
此段代码为某程序解密函数,求转换为加密函数
问题相关代码
public static string Decrypt(string Text, string sKey = "")
{
DESCryptoServiceProvider dESCryptoServiceProvider = new DESCryptoServiceProvider();
int num = Text.Length / 2;
byte[] array = new byte[num];
for (int i = 0; i < num; i++)
{
int num2 = Convert.ToInt32(Text.Substring(i * 2, 2), 16);
array[i] = (byte)num2;
}
dESCryptoServiceProvider.Key = Encoding.ASCII.GetBytes(MD5(sKey).Substring(0, 1));
dESCryptoServiceProvider.IV = Encoding.ASCII.GetBytes(MD5(sKey).Substring(0, 1));
MemoryStream memoryStream = new MemoryStream();
CryptoStream cryptoStream = new CryptoStream(memoryStream, dESCryptoServiceProvider.CreateDecryptor(), CryptoStreamMode.Write);
cryptoStream.Write(array, 0, array.Length);
cryptoStream.FlushFinalBlock();
return Encoding.Default.GetString(memoryStream.ToArray());
}