利用windows提供的advapi32.dll进行MD5加密

利用windows提供的advapi32.dll进行MD5加密

#include

/* 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

/*
* MTS: Each of these assumes MD5_CTX is locked against simultaneous use.
*/
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;
}

int main()
{
MD5_CTX ctx;
unsigned char buf[10] = “Xiaozhou”;
HINSTANCE hDLL;

if ( (hDLL = LoadLibrary(“advapi32.dll”)) > 0 )
{
MD5Init = (PMD5Init)GetProcAddress(hDLL,”MD5Init”);
MD5Update = (PMD5Update)GetProcAddress(hDLL,”MD5Update”);
MD5Final = (PMD5Final)GetProcAddress(hDLL,”MD5Final”);

MD5Init(&ctx);
MD5Update(&ctx,buf,8);
MD5Final(&ctx);

printf(“%s \n”,Hex2ASC(ctx.digest,16));

}

return 0;
}

 
 

1.使用openssl库

编写test.cpp文件
  1. #include<stdio.h>
  2. #include<openssl/md5.h>
  3. #include<string.h>

  4. int main( int argc, char **argv )
  5. {
  6. MD5_CTX ctx;
  7. char *data="19870617";
  8. unsigned char md[16];
  9. char buf[33]={'\0'};
  10. char tmp[3]={'\0'};
  11. int i;

  12. MD5_Init(&ctx);
  13. MD5_Update(&ctx,(unsigned char *)data,strlen(data));
  14. MD5_Final(md,&ctx);

  15. for( i=0; i<16; i++ ){
  16. sprintf(tmp,"%02X",md[i]);
  17. //sprintf(tmp, "%2.2x", md[i]);
  18. strcat(buf,tmp);
  19. }
  20. printf("%s\n",buf);
  21. return 0;
  22. }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
“ConsoleApplication2.exe”(Win32): 已加载“D:\vsceshi\ConsoleApplication2\x64\Debug\ConsoleApplication2.exe”。已加载符号。 “ConsoleApplication2.exe”(Win32): 已加载“C:\Windows\System32\ntdll.dll”。无法查找或打开 PDB 文件。 “ConsoleApplication2.exe”(Win32): 已加载“C:\Windows\System32\kernel32.dll”。无法查找或打开 PDB 文件。 “ConsoleApplication2.exe”(Win32): 已加载“C:\Windows\System32\KernelBase.dll”。无法查找或打开 PDB 文件。 “ConsoleApplication2.exe”(Win32): 已加载“C:\Windows\System32\msvcp140d.dll”。无法查找或打开 PDB 文件。 “ConsoleApplication2.exe”(Win32): 已加载“C:\Windows\System32\vcruntime140d.dll”。无法查找或打开 PDB 文件。 “ConsoleApplication2.exe”(Win32): 已加载“C:\Windows\System32\vcruntime140d.dll”。无法查找或打开 PDB 文件。 “ConsoleApplication2.exe”(Win32): 已加载“C:\Windows\System32\ucrtbased.dll”。无法查找或打开 PDB 文件。 “ConsoleApplication2.exe”(Win32): 已卸载“C:\Windows\System32\vcruntime140d.dll” “ConsoleApplication2.exe”(Win32): 已加载“C:\Windows\System32\advapi32.dll”。无法查找或打开 PDB 文件。 “ConsoleApplication2.exe”(Win32): 已加载“C:\Windows\System32\ucrtbased.dll”。无法查找或打开 PDB 文件。 “ConsoleApplication2.exe”(Win32): 已卸载“C:\Windows\System32\ucrtbased.dll” “ConsoleApplication2.exe”(Win32): 已加载“C:\Windows\System32\msvcrt.dll”。无法查找或打开 PDB 文件。 “ConsoleApplication2.exe”(Win32): 已加载“C:\Windows\System32\sechost.dll”。无法查找或打开 PDB 文件。 “ConsoleApplication2.exe”(Win32): 已加载“C:\Windows\System32\rpcrt4.dll”。无法查找或打开 PDB 文件。 “ConsoleApplication2.exe”(Win32): 已加载“C:\Windows\System32\cryptbase.dll”。无法查找或打开 PDB 文件。 “ConsoleApplication2.exe”(Win32): 已加载“C:\Windows\System32\kernel.appcore.dll”。无法查找或打开 PDB 文件。
07-17

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值