高分求助 小弟我要用DES算法解密配置文件,然后把解密后的内容写入内存中,请问怎么做,最好给出代码 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你是要写内存的代码还是DES算法的代码?DES算法就是调用方法返回值就行了c#是一般不能直接操作内存的 private static readonly string DESKey = "ABCDEFGH";//这是加密算法的密钥,对于Key的要求是:长度只能是八个字节. private static readonly string DESIV = "HGFEDCBA";//这是初始化向量,对于IV的要求是:长度也只能是八个字节. /// <summary> /// 传递要加密的文本,返回加密之后的文本,即密文 /// </summary> /// <param name="aBeforeString"></param> /// <returns></returns> public static string Encrypt(string aBeforeString) { byte[] arrDESKey; byte[] arrDESIV; MemoryStream ms = new MemoryStream();//这是采用内存流的方式加密文本,加密后直接以字节流的方式返回密文. DESCryptoServiceProvider objDES; ICryptoTransform objEncryptor; CryptoStream objCryptoStream; arrDESKey = Convert2ByteArray(DESKey); arrDESIV = Convert2ByteArray(DESIV); objDES = new DESCryptoServiceProvider(); objEncryptor = objDES.CreateEncryptor(arrDESKey, arrDESIV); objCryptoStream = new CryptoStream(ms, objEncryptor, CryptoStreamMode.Write); StreamWriter sw = new StreamWriter(objCryptoStream); sw.Write(aBeforeString); // Close the StreamWriter and CryptoStream. sw.Close(); objCryptoStream.Close(); // Get an array of bytes that represents // the memory stream. byte[] buffer = ms.ToArray(); // Close the memory stream. ms.Close(); string aString = ""; for (int i = 0; i < buffer.Length; i++) { aString = aString + BitConverter.ToChar(buffer, i).ToString();//在这里对于密文//做了进一步的处理,将相临的两个字节组合成一个16位的Unicode字符 i = i + 1; } return aString; } public static string Decrypt(string aAferterString)//解密密文,返回原文本. { byte[] arrDESKey; byte[] arrDESIV; DESCryptoServiceProvider objDES; ICryptoTransform objDecryptor; CryptoStream objCryptoStream; MemoryStream ms = new MemoryStream(ConvertStringTOByte(aAferterString)); arrDESKey = Convert2ByteArray(DESKey); arrDESIV = Convert2ByteArray(DESIV); objDES = new DESCryptoServiceProvider(); objDecryptor = objDES.CreateDecryptor(arrDESKey, arrDESIV); objCryptoStream = new CryptoStream(ms, objDecryptor, CryptoStreamMode.Read);//解密是采取和加密相反的方式进行解密. StreamReader sr = new StreamReader(objCryptoStream); // Read the stream as a string. string val = sr.ReadToEnd(); // Close the streams. sr.Close(); objCryptoStream.Close(); ms.Close(); //objFileStream.Close(); return val; } 估计要调用windows API 中 WriteProcessMemory来处理了。 textBox文本框输入值后如何自动将值添加到datagridview中 WebRequest和WebResponse中字节码转换问题 c# 中怎么创建文件夹呀 ? 关于datagrid页眉问题,难道就没有人做出来吗?? 了解ftp协议的朋友请进 半角/全角转换 Net WCF遍历方法参数 HttpWebRequest登录某https网站失败的问题 请问用什么方法检测自己的计算机与万维网相连? 谁有类似于QQ的控件或者源码啊?小弟想参考一下 想找.net(c#)有桌面/web开发经验的程序员一起创业!有兴趣者进! 如何旋转TxtBox文本框
DES算法就是调用方法返回值就行了c#是一般不能直接操作内存的
private static readonly string DESIV = "HGFEDCBA";//这是初始化向量,对于IV的要求是:长度也只能是八个字节. /// <summary>
/// 传递要加密的文本,返回加密之后的文本,即密文
/// </summary>
/// <param name="aBeforeString"></param>
/// <returns></returns>
public static string Encrypt(string aBeforeString)
{
byte[] arrDESKey;
byte[] arrDESIV;
MemoryStream ms = new MemoryStream();//这是采用内存流的方式加密文本,加密后直接以字节流的方式返回密文.
DESCryptoServiceProvider objDES;
ICryptoTransform objEncryptor;
CryptoStream objCryptoStream;
arrDESKey = Convert2ByteArray(DESKey);
arrDESIV = Convert2ByteArray(DESIV);
objDES = new DESCryptoServiceProvider();
objEncryptor = objDES.CreateEncryptor(arrDESKey, arrDESIV);
objCryptoStream = new CryptoStream(ms, objEncryptor, CryptoStreamMode.Write);
StreamWriter sw = new StreamWriter(objCryptoStream);
sw.Write(aBeforeString);
// Close the StreamWriter and CryptoStream.
sw.Close();
objCryptoStream.Close();
// Get an array of bytes that represents
// the memory stream.
byte[] buffer = ms.ToArray();
// Close the memory stream.
ms.Close();
string aString = "";
for (int i = 0; i < buffer.Length; i++)
{
aString = aString + BitConverter.ToChar(buffer, i).ToString();//在这里对于密文//做了进一步的处理,将相临的两个字节组合成一个16位的Unicode字符
i = i + 1;
}
return aString;
} public static string Decrypt(string aAferterString)//解密密文,返回原文本.
{
byte[] arrDESKey;
byte[] arrDESIV;
DESCryptoServiceProvider objDES;
ICryptoTransform objDecryptor;
CryptoStream objCryptoStream;
MemoryStream ms = new MemoryStream(ConvertStringTOByte(aAferterString));
arrDESKey = Convert2ByteArray(DESKey);
arrDESIV = Convert2ByteArray(DESIV);
objDES = new DESCryptoServiceProvider();
objDecryptor = objDES.CreateDecryptor(arrDESKey, arrDESIV);
objCryptoStream = new CryptoStream(ms, objDecryptor, CryptoStreamMode.Read);//解密是采取和加密相反的方式进行解密.
StreamReader sr = new StreamReader(objCryptoStream);
// Read the stream as a string.
string val = sr.ReadToEnd();
// Close the streams.
sr.Close();
objCryptoStream.Close();
ms.Close();
//objFileStream.Close();
return val;
}