日期:2014-05-18  浏览次数:20528 次

50分 求一简单的ASP.net代码
小弟不是做.net的,但现在需要用.net调用DLL里的方法对字符串加密,并保存到数据库里,特来此求救,那位仁慈的大哥帮帮小弟,不胜感激。谢了。

dll文件名:TmWebDC114.dll
加密方法:     int   TW_DeCryptSim(unsigned   char   *pBuf,int   iLen,unsigned   char   *pOutBuf,int   iOutLen);
数据库类型   MSSql
数据库地址:   192.168.2.66    
数据库名:student
帐号:administrator
密码   :rotartsinimda
表:student(id,name,password)
name,password是用get方法得到的。
需要对password加密然后添加到数据库里。

谢了
谢了
谢了!!!!!!!!!!!!!!!!!!!!!!!!!!!1


------解决方案--------------------
public static string MD5(string data)
{
byte[] byteData = System.Text.Encoding.UTF32.GetBytes(data);
StringBuilder result = new StringBuilder();

MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
byte[] encryptByteData = md5.ComputeHash(byteData);
foreach (byte b in encryptByteData)
{
result.Append(b.ToString( "X2 "));
}

return result.ToString();
}
------解决方案--------------------
用MD5加密就行了,方便,既然加密了你还解密干什么啊
------解决方案--------------------
3DES
------解决方案--------------------
提供一个基于.NET的加密/解密算法
提供一个基于.NET SymmetricAlgorithm 类的、带私钥的加密/解密算法的包装类。使用方法:

SymmCrypto de = new SymmCrypto(SymmCrypto.SymmProvEnum.DES);
Response.Write(x.Decrypting(de.Encrypting( "ok ", "yyy "), "yyy "));
类的实现C#编码

using System;
using System.Security.Cryptography;
using System.IO;
using System.Text;

namespace eMeng
{
/// <summary>
/// SymmCrypto 的摘要说明。
/// SymmCrypto类实现.NET框架下的加密和解密服务。
/// 原作者: Frank Fang : fangfrank@hotmail.com
/// </summary>
public class SymmCrypto
{
public enum SymmProvEnum : int
{
DES, RC2, Rijndael
}

private SymmetricAlgorithm mobjCryptoService;

/// <remarks>
/// 使用.Net SymmetricAlgorithm 类的构造器.
/// </remarks>
public SymmCrypto(SymmProvEnum NetSelected)
{
switch (NetSelected)
{
case SymmProvEnum.DES:
mobjCryptoService = new DESCryptoServiceProvider();
break;
case SymmProvEnum.RC2:
mobjCryptoService = new RC2CryptoServiceProvider();
break;
case SymmProvEnum.Rijndael:
mobjCryptoService = new RijndaelManaged();
break;
}
}

/// <remarks>
/// 使用自定义SymmetricAlgorithm类的构造器.
/// </remarks>
public SymmCrypto(SymmetricAlgorithm ServiceProvider)
{
mobjCryptoService = ServiceProvider;
}

/// <remarks>
/// Depending on the legal key size limitations of
/// a specific CryptoService provider and length of
/// the private key provided, padding the secret key
/// with space character to meet the legal size of the algorithm.
/// </remarks>
private byte[] GetLegalKey(string Key)
{
string sTemp;
if (mobjCryptoService.LegalKeySizes.Length > 0)
{
int lessSize = 0, moreSize = mobjCryptoService.LegalKeySizes[0].MinSize;
// key sizes are in bits
while (Key.Length * 8 > moreSize)
{
lessSize = moreSize;