md5_hash.c
上传用户:s81996212
上传日期:2007-01-04
资源大小:722k
文件大小:1k
- /*
- ** Copyright 2000 Double Precision, Inc.
- ** See COPYING for distribution information.
- */
- #include "md5.h"
- static const char base64tab[]=
- "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
- const char *md5_hash(const char *passw)
- {
- MD5_DIGEST md5buf;
- static char hash_buffer[sizeof("{MD5}")+ (sizeof(md5buf)+2)/3*4];
- int a=0,b=0,c=0;
- int i, j;
- int d, e, f, g;
- md5_digest(passw, strlen(passw), md5buf);
- strcpy(hash_buffer, "{MD5}");
- j=5;
- for (i=0; i<sizeof(md5buf); i += 3)
- {
- a=md5buf[i];
- b= i+1 < sizeof(md5buf) ? md5buf[i+1]:0;
- c= i+2 < sizeof(md5buf) ? md5buf[i+2]:0;
- d=base64tab[ a >> 2 ];
- e=base64tab[ ((a & 3 ) << 4) | (b >> 4)];
- f=base64tab[ ((b & 15) << 2) | (c >> 6)];
- g=base64tab[ c & 63 ];
- if (i + 1 >= sizeof(md5buf)) f='=';
- if (i + 2 >= sizeof(md5buf)) g='=';
- hash_buffer[j++]=d;
- hash_buffer[j++]=e;
- hash_buffer[j++]=f;
- hash_buffer[j++]=g;
- }
- hash_buffer[j]=0;
- return (hash_buffer);
- }