易语言的DES算法解密和C#的算法不一样吗?
好像C#的算法有2个密钥
using System;
using System.Data;
using System.Text;
using System.Security.Cryptography;
using System.IO;
using System.Runtime.InteropServices;
namespace DesForAsp
{
[ComVisible(true)]
public interface iDes
{
string encode(string explainText, string desKey);
string decode(string encryptText, string desKey);
}
[ComVisible(true)]
[ClassInterface(ClassInterfaceType.AutoDual)]
public class Des:iDes
{
public Des(){
}
public string encode(string explainText, string desKey)
{
try
{
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
des.Mode = CipherMode.ECB;
des.Key = System.Text.Encoding.UTF8.GetBytes(desKey);
des.IV = des.Key;
byte[] inputByteArray = System.Text.Encoding.UTF8.GetBytes(explainText);
MemoryStream ms = new MemoryStream();
CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(), CryptoStreamMode.Write);
cs.Write(inputByteArray, 0, inputByteArray.Length);
cs.FlushFinalBlock();
return Convert.ToBase64String(ms.ToArray());
}
catch (System.Exception e)
{
return e.ToString();
}
}
public string decode(string encryptText, string desKey)
{
try
{
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
des.Mode = CipherMode.ECB;
des.Key = System.Text.Encoding.UTF8.GetBytes(desKey);
des.IV = des.Key;
byte[] inputByteArray = Convert.FromBase64String(encryptText);
MemoryStream ms = new MemoryStream();
CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(), CryptoStreamMode.Write);
cs.Write(inputByteArray, 0, inputByteArray.Length);
cs.FlushFinalBlock();
System.Text.Encoding encoding = new System.Text.UTF8Encoding();
return encoding.GetString(ms.ToArray());
}
catch (System.Exception e)
{
return e.ToString();
}
}
}
}
-----------------------------------
易语言自带的支持库不是标准的DES算法
这里有个DES标准算法的易模块,经测试算法结果和c#的一样
http://bbs.eyuyan.com/read.php?tid=176976
[招生]科锐逆向工程师培训(2024年11月15日实地,远程教学同时开班, 第51期)