vc下MD5加密函数

/* Data structure for MD5 (Message-Digest) computation */
typedef struct {
ULONG i[2]; /* number of _bits_ handled mod 2^64 */
ULONG buf[4]; /* scratch buffer */
unsigned char in[64]; /* input buffer */
unsigned char digest[16]; /* actual digest after MD5Final call */
} MD5_CTX;


#define MD5DIGESTLEN 16

#define PROTO_LIST(list) list

typedef void (WINAPI* PMD5Init) PROTO_LIST ((MD5_CTX *));
typedef void (WINAPI* PMD5Update) PROTO_LIST ((MD5_CTX *, const unsigned char *, unsigned int));
typedef void (WINAPI* PMD5Final )PROTO_LIST ((MD5_CTX *));


PMD5Init MD5Init = NULL;
PMD5Update MD5Update = NULL;
PMD5Final MD5Final = NULL;

const char * Hex2ASC(const BYTE *Hex, int Len)
{
static char ASC[4096 * 2];
int i;

for (i = 0; i < Len; i++)
{
ASC[i * 2] = "0123456789abcdef"[Hex[i] >> 4];
ASC[i * 2 + 1] = "0123456789abcdef"[Hex[i] & 0x0F];
}
ASC[i * 2] = '/0';
return ASC;
}


const char * md5(const char * str)
{
MD5_CTX ctx;
unsigned char * buf = (unsigned char *)(str);
int len = strlen(str);
HINSTANCE hDLL;
if ( (hDLL = LoadLibrary("advapi32.dll")) > 0 )
{

PMD5Init MD5Init = (PMD5Init)GetProcAddress(hDLL,"MD5Init");
PMD5Update MD5Update = (PMD5Update)GetProcAddress(hDLL,"MD5Update");
PMD5Final MD5Final = (PMD5Final)GetProcAddress(hDLL,"MD5Final");

MD5Init(&ctx);
MD5Update(&ctx, buf, len);
MD5Final(&ctx);
}
return Hex2ASC(ctx.digest, 16);
}

Powered by Zoundry Raven

  • 0
    点赞
  • 0
    评论
  • 0
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

©️2021 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值