日期:2014-05-17 浏览次数:21264 次
extern "C" __declspec(dllexport) char * MDString (char tmp[128])
{
unsigned char digest[16];
MD5_CTX context;
/*scanf("%s",tmp);*/
int result ;
char *cString=new char;
MD5Init (&context);
int len=strlen(tmp);
MD5Update (&context, (unsigned char*)tmp, len);
MD5Final (digest,&context);
char * msg = new char;
/*printf("MD5Value:");*/
for(int i=0; i<16; ++i)
{
sprintf(msg,"%02X",digest[i]);
return_char[i*2] = msg[0];
return_char[i*2+1] =msg[1];
}
//sprintf(cString, "%d", result);
return return_char;
}
[DllImport("pathjiami.dll", CallingConvention = CallingConvention.Cdecl)]
public extern static string MDString(string tmp);
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string str = txt.Text;
//<<<<< 2013-03-20
//string txtStr = "";
////int len = str.Length;
//Encoding code = Encoding.GetEncoding("unicode");
//byte[] arr = code.GetBytes(str);
//foreach (byte ch in arr)
// txtStr += Convert.ToString(ch, 16);
//>>>>>
string msg = MDString(str);
//接收C++md5加密结果.
txt2.Text = msg;
//接收C#md5加密结果.
txt3.Text = StringToMD5Hash(str);
}
public string StringToMD5Hash(string inputString)
{
MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
byte[] encryptedBytes = md5.ComputeHash(Encoding.ASCII.GetBytes(inputString);