精华内容
下载资源
问答
  • 摘要:VC/C++源码,文件操作,MD5,加密 文件多层MD5加密工具(附VC6源码),大学时代与同学聊到最简单的加密方法,谈到直接修改文件前几个字节,就可以让一些文件打不开。因此,一时兴起,就写了这么个工具。工具简单...
  • 文件多层MD5加密工具(附VC6源码)

    千次阅读 热门讨论 2012-12-19 19:53:45
    大学时代与同学聊到最简单的加密方法,谈到直接修改文件前几个字节,就可以让一些文件打不开。  因此,一时兴起,就写了这么个工具。  工具简单,操作也不多说。... 下载地址:文件多层MD5加密工具(附VC6源码)

      大学时代与同学聊到最简单的加密方法,谈到直接修改文件前几个字节,就可以让一些文件打不开。

      因此,一时兴起,就写了这么个工具。

      工具简单,操作也不多说。附上源码,供参考。



      下载地址:文件多层MD5加密工具(附VC6源码)


    展开全文
  • 环境:vc2003 ... 1 /* MD5.H - header file for MD5C.C 2 */ 3 4 /* Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All 5 rights reserved. 6 7 License to copy and use th...

    环境:vc2003 

    .h

     1 /* MD5.H - header file for MD5C.C
     2  */
     3 
     4 /* Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All
     5 rights reserved.
     6 
     7 License to copy and use this software is granted provided that it
     8 is identified as the "RSA Data Security, Inc. MD5 Message-Digest
     9 Algorithm" in all material mentioning or referencing this software
    10 or this function.
    11 
    12 License is also granted to make and use derivative works provided
    13 that such works are identified as "derived from the RSA Data
    14 Security, Inc. MD5 Message-Digest Algorithm" in all material
    15 mentioning or referencing the derived work.
    16 
    17 RSA Data Security, Inc. makes no representations concerning either
    18 the merchantability of this software or the suitability of this
    19 software for any particular purpose. It is provided "as is"
    20 without express or implied warranty of any kind.
    21 
    22 These notices must be retained in any copies of any part of this
    23 documentation and/or software.
    24  */
    25 
    26 #ifndef MD5_SECRIT_H__
    27 #define MD5_SECRIT_H__
    28 
    29 namespace SECRIET
    30 {
    31     /* MD5 context. */
    32     typedef unsigned int uint32_t;
    33     typedef struct {
    34     uint32_t state[4];            /* state (ABCD) */
    35     uint32_t count[2];            /* number of bits, modulo 2^64 (lsb first) */
    36     unsigned char buffer[64];     /* input buffer */
    37     } MD5_CTX;
    38 
    39     void MD5Init(MD5_CTX *context);
    40     void MD5Update(MD5_CTX *context, unsigned char *input, unsigned int inputLen);
    41     void MD5Final(unsigned char digest[16], MD5_CTX *context);
    42 
    43     class CMD5
    44     {
    45     public:
    46         MD5_CTX _ctxMd5;
    47 
    48     public:
    49         CMD5() {MD5Init(&_ctxMd5);}
    50         ~CMD5() {}
    51 
    52     public:
    53         void Encode( unsigned char *input, unsigned int inputLen, unsigned char digest[16] )
    54         {
    55             MD5Update( &_ctxMd5, input, inputLen );
    56             MD5Final( digest, &_ctxMd5);
    57         }
    58 
    59     };
    60 }
    61 #endif

    .cpp

      1 /*
      2  * MD5C.C - RSA Data Security, Inc., MD5 message-digest algorithm
      3  */
      4 
      5 /*
      6  * Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All rights
      7  * reserved.
      8  * 
      9  * License to copy and use this software is granted provided that it is
     10  * identified as the "RSA Data Security, Inc. MD5 Message-Digest Algorithm"
     11  * in all material mentioning or referencing this software or this function.
     12  * 
     13  * License is also granted to make and use derivative works provided that such
     14  * works are identified as "derived from the RSA Data Security, Inc. MD5
     15  * Message-Digest Algorithm" in all material mentioning or referencing the
     16  * derived work.
     17  * 
     18  * RSA Data Security, Inc. makes no representations concerning either the
     19  * merchantability of this software or the suitability of this software for
     20  * any particular purpose. It is provided "as is" without express or implied
     21  * warranty of any kind.
     22  * 
     23  * These notices must be retained in any copies of any part of this
     24  * documentation and/or software.
     25  */
     26 
     27 #include "Stdafx.h"
     28 #include "md5.h"
     29 
     30 /*
     31  * Constants for MD5Transform routine.
     32  */
     33 #define S11 7
     34 #define S12 12
     35 #define S13 17
     36 #define S14 22
     37 #define S21 5
     38 #define S22 9
     39 #define S23 14
     40 #define S24 20
     41 #define S31 4
     42 #define S32 11
     43 #define S33 16
     44 #define S34 23
     45 #define S41 6
     46 #define S42 10
     47 #define S43 15
     48 #define S44 21
     49 
     50 namespace SECRIET
     51 {
     52 
     53     static unsigned char PADDING[64] = {
     54         0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
     55         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
     56         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
     57     };
     58 
     59     /*
     60     * F, G, H and I are basic MD5 functions.
     61     */
     62     #define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
     63     #define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
     64     #define H(x, y, z) ((x) ^ (y) ^ (z))
     65     #define I(x, y, z) ((y) ^ ((x) | (~z)))
     66 
     67     /*
     68     * ROTATE_LEFT rotates x left n bits.
     69     */
     70     #define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
     71 
     72     /*
     73     * FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. Rotation is
     74     * separate from addition to prevent recomputation.
     75     */
     76     #define FF(a, b, c, d, x, s, ac) { \
     77     (a) += F ((b), (c), (d)) + (x) + (uint32_t)(ac); \
     78     (a) = ROTATE_LEFT ((a), (s)); \
     79     (a) += (b); \
     80     }
     81     #define GG(a, b, c, d, x, s, ac) { \
     82     (a) += G ((b), (c), (d)) + (x) + (uint32_t)(ac); \
     83     (a) = ROTATE_LEFT ((a), (s)); \
     84     (a) += (b); \
     85     }
     86     #define HH(a, b, c, d, x, s, ac) { \
     87     (a) += H ((b), (c), (d)) + (x) + (uint32_t)(ac); \
     88     (a) = ROTATE_LEFT ((a), (s)); \
     89     (a) += (b); \
     90     }
     91     #define II(a, b, c, d, x, s, ac) { \
     92     (a) += I ((b), (c), (d)) + (x) + (uint32_t)(ac); \
     93     (a) = ROTATE_LEFT ((a), (s)); \
     94     (a) += (b); \
     95     }
     96 
     97     /*
     98     * Encodes input (uint32_t) into output (unsigned char). Assumes len is a
     99     * multiple of 4.
    100     */
    101     static void 
    102     Encode(unsigned char *output, uint32_t * input, unsigned int len)
    103     {
    104         unsigned int    i, j;
    105 
    106 //        ASSERT((len % 4) == 0);
    107 
    108         for (i = 0, j = 0; j < len; i++, j += 4) {
    109             output[j] = (unsigned char) (input[i] & 0xff);
    110             output[j + 1] = (unsigned char) ((input[i] >> 8) & 0xff);
    111             output[j + 2] = (unsigned char) ((input[i] >> 16) & 0xff);
    112             output[j + 3] = (unsigned char) ((input[i] >> 24) & 0xff);
    113         }
    114     }
    115 
    116     /*
    117     * Decodes input (unsigned char) into output (uint32_t). Assumes len is a
    118     * multiple of 4.
    119     */
    120     static void 
    121     Decode(uint32_t * output, unsigned char *input, unsigned int len)
    122     {
    123         unsigned int    i, j;
    124 
    125         for (i = 0, j = 0; j < len; i++, j += 4)
    126             output[i] = ((uint32_t) input[j]) | (((uint32_t) input[j + 1]) << 8) |
    127                 (((uint32_t) input[j + 2]) << 16) | (((uint32_t) input[j + 3]) << 24);
    128     }
    129 
    130     /*
    131     * MD5 basic transformation. Transforms state based on block.
    132     */
    133     static void 
    134     MD5Transform(uint32_t state[4], unsigned char block[64])
    135     {
    136         uint32_t           a = state[0], b = state[1], c = state[2], d = state[3],
    137                         x[16];
    138 
    139         Decode(x, block, 64);
    140 
    141         /* Round 1 */
    142         FF(a, b, c, d, x[0], S11, 0xd76aa478);    /* 1 */
    143         FF(d, a, b, c, x[1], S12, 0xe8c7b756);    /* 2 */
    144         FF(c, d, a, b, x[2], S13, 0x242070db);    /* 3 */
    145         FF(b, c, d, a, x[3], S14, 0xc1bdceee);    /* 4 */
    146         FF(a, b, c, d, x[4], S11, 0xf57c0faf);    /* 5 */
    147         FF(d, a, b, c, x[5], S12, 0x4787c62a);    /* 6 */
    148         FF(c, d, a, b, x[6], S13, 0xa8304613);    /* 7 */
    149         FF(b, c, d, a, x[7], S14, 0xfd469501);    /* 8 */
    150         FF(a, b, c, d, x[8], S11, 0x698098d8);    /* 9 */
    151         FF(d, a, b, c, x[9], S12, 0x8b44f7af);    /* 10 */
    152         FF(c, d, a, b, x[10], S13, 0xffff5bb1);    /* 11 */
    153         FF(b, c, d, a, x[11], S14, 0x895cd7be);    /* 12 */
    154         FF(a, b, c, d, x[12], S11, 0x6b901122);    /* 13 */
    155         FF(d, a, b, c, x[13], S12, 0xfd987193);    /* 14 */
    156         FF(c, d, a, b, x[14], S13, 0xa679438e);    /* 15 */
    157         FF(b, c, d, a, x[15], S14, 0x49b40821);    /* 16 */
    158 
    159         /* Round 2 */
    160         GG(a, b, c, d, x[1], S21, 0xf61e2562);    /* 17 */
    161         GG(d, a, b, c, x[6], S22, 0xc040b340);    /* 18 */
    162         GG(c, d, a, b, x[11], S23, 0x265e5a51);    /* 19 */
    163         GG(b, c, d, a, x[0], S24, 0xe9b6c7aa);    /* 20 */
    164         GG(a, b, c, d, x[5], S21, 0xd62f105d);    /* 21 */
    165         GG(d, a, b, c, x[10], S22, 0x2441453);    /* 22 */
    166         GG(c, d, a, b, x[15], S23, 0xd8a1e681);    /* 23 */
    167         GG(b, c, d, a, x[4], S24, 0xe7d3fbc8);    /* 24 */
    168         GG(a, b, c, d, x[9], S21, 0x21e1cde6);    /* 25 */
    169         GG(d, a, b, c, x[14], S22, 0xc33707d6);    /* 26 */
    170         GG(c, d, a, b, x[3], S23, 0xf4d50d87);    /* 27 */
    171         GG(b, c, d, a, x[8], S24, 0x455a14ed);    /* 28 */
    172         GG(a, b, c, d, x[13], S21, 0xa9e3e905);    /* 29 */
    173         GG(d, a, b, c, x[2], S22, 0xfcefa3f8);    /* 30 */
    174         GG(c, d, a, b, x[7], S23, 0x676f02d9);    /* 31 */
    175         GG(b, c, d, a, x[12], S24, 0x8d2a4c8a);    /* 32 */
    176 
    177         /* Round 3 */
    178         HH(a, b, c, d, x[5], S31, 0xfffa3942);    /* 33 */
    179         HH(d, a, b, c, x[8], S32, 0x8771f681);    /* 34 */
    180         HH(c, d, a, b, x[11], S33, 0x6d9d6122);    /* 35 */
    181         HH(b, c, d, a, x[14], S34, 0xfde5380c);    /* 36 */
    182         HH(a, b, c, d, x[1], S31, 0xa4beea44);    /* 37 */
    183         HH(d, a, b, c, x[4], S32, 0x4bdecfa9);    /* 38 */
    184         HH(c, d, a, b, x[7], S33, 0xf6bb4b60);    /* 39 */
    185         HH(b, c, d, a, x[10], S34, 0xbebfbc70);    /* 40 */
    186         HH(a, b, c, d, x[13], S31, 0x289b7ec6);    /* 41 */
    187         HH(d, a, b, c, x[0], S32, 0xeaa127fa);    /* 42 */
    188         HH(c, d, a, b, x[3], S33, 0xd4ef3085);    /* 43 */
    189         HH(b, c, d, a, x[6], S34, 0x4881d05);    /* 44 */
    190         HH(a, b, c, d, x[9], S31, 0xd9d4d039);    /* 45 */
    191         HH(d, a, b, c, x[12], S32, 0xe6db99e5);    /* 46 */
    192         HH(c, d, a, b, x[15], S33, 0x1fa27cf8);    /* 47 */
    193         HH(b, c, d, a, x[2], S34, 0xc4ac5665);    /* 48 */
    194 
    195         /* Round 4 */
    196         II(a, b, c, d, x[0], S41, 0xf4292244);    /* 49 */
    197         II(d, a, b, c, x[7], S42, 0x432aff97);    /* 50 */
    198         II(c, d, a, b, x[14], S43, 0xab9423a7);    /* 51 */
    199         II(b, c, d, a, x[5], S44, 0xfc93a039);    /* 52 */
    200         II(a, b, c, d, x[12], S41, 0x655b59c3);    /* 53 */
    201         II(d, a, b, c, x[3], S42, 0x8f0ccc92);    /* 54 */
    202         II(c, d, a, b, x[10], S43, 0xffeff47d);    /* 55 */
    203         II(b, c, d, a, x[1], S44, 0x85845dd1);    /* 56 */
    204         II(a, b, c, d, x[8], S41, 0x6fa87e4f);    /* 57 */
    205         II(d, a, b, c, x[15], S42, 0xfe2ce6e0);    /* 58 */
    206         II(c, d, a, b, x[6], S43, 0xa3014314);    /* 59 */
    207         II(b, c, d, a, x[13], S44, 0x4e0811a1);    /* 60 */
    208         II(a, b, c, d, x[4], S41, 0xf7537e82);    /* 61 */
    209         II(d, a, b, c, x[11], S42, 0xbd3af235);    /* 62 */
    210         II(c, d, a, b, x[2], S43, 0x2ad7d2bb);    /* 63 */
    211         II(b, c, d, a, x[9], S44, 0xeb86d391);    /* 64 */
    212 
    213         state[0] += a;
    214         state[1] += b;
    215         state[2] += c;
    216         state[3] += d;
    217 
    218         /*
    219         * Zeroize sensitive information.
    220         */
    221         memset((unsigned char *) x, 0, sizeof(x));
    222     }
    223 
    224     /**
    225     * MD5Init:
    226     * @context: MD5 context to be initialized.
    227     * 
    228     * Initializes MD5 context for the start of message digest computation.
    229     **/
    230     void 
    231     MD5Init(MD5_CTX * context)
    232     {
    233         context->count[0] = context->count[1] = 0;
    234         /* Load magic initialization constants.  */
    235         context->state[0] = 0x67452301;
    236         context->state[1] = 0xefcdab89;
    237         context->state[2] = 0x98badcfe;
    238         context->state[3] = 0x10325476;
    239     }
    240 
    241     /**
    242     * MD5Update:
    243     * @context: MD5 context to be updated.
    244     * @input: pointer to data to be fed into MD5 algorithm.
    245     * @inputLen: size of @input data in bytes.
    246     * 
    247     * MD5 block update operation. Continues an MD5 message-digest operation,
    248     * processing another message block, and updating the context.
    249     **/
    250 
    251     void 
    252     MD5Update(MD5_CTX * context, unsigned char *input, unsigned int inputLen)
    253     {
    254         unsigned int    i, index, partLen;
    255 
    256         /* Compute number of bytes mod 64 */
    257         index = (unsigned int) ((context->count[0] >> 3) & 0x3F);
    258 
    259         /* Update number of bits */
    260         if ((context->count[0] += ((uint32_t) inputLen << 3)) < ((uint32_t) inputLen << 3)) {
    261             context->count[1]++;
    262         }
    263         context->count[1] += ((uint32_t) inputLen >> 29);
    264 
    265         partLen = 64 - index;
    266 
    267         /* Transform as many times as possible.  */
    268         if (inputLen >= partLen) {
    269             memcpy((unsigned char *) & context->buffer[index], (unsigned char *) input, partLen);
    270             MD5Transform(context->state, context->buffer);
    271 
    272             for (i = partLen; i + 63 < inputLen; i += 64) {
    273                 MD5Transform(context->state, &input[i]);
    274             }
    275             index = 0;
    276         } else {
    277             i = 0;
    278         }
    279         /* Buffer remaining input */
    280         if ((inputLen - i) != 0) {
    281             memcpy((unsigned char *) & context->buffer[index], (unsigned char *) & input[i], inputLen - i);
    282         }
    283     }
    284 
    285     /**
    286     * MD5Final:
    287     * @digest: 16-byte buffer to write MD5 checksum.
    288     * @context: MD5 context to be finalized.
    289     * 
    290     * Ends an MD5 message-digest operation, writing the the message
    291     * digest and zeroing the context.  The context must be initialized
    292     * with MD5Init() before being used for other MD5 checksum calculations.
    293     **/
    294 
    295     void 
    296     MD5Final(unsigned char digest[16], MD5_CTX * context)
    297     {
    298         unsigned char   bits[8];
    299         unsigned int    index, padLen;
    300 
    301         /* Save number of bits */
    302         Encode(bits, context->count, 8);
    303 
    304         /*
    305         * Pad out to 56 mod 64.
    306         */
    307         index = (unsigned int) ((context->count[0] >> 3) & 0x3f);
    308         padLen = (index < 56) ? (56 - index) : (120 - index);
    309         MD5Update(context, PADDING, padLen);
    310 
    311         /* Append length (before padding) */
    312         MD5Update(context, bits, 8);
    313         /* Store state in digest */
    314         Encode(digest, context->state, 16);
    315 
    316         /*
    317         * Zeroize sensitive information.
    318         */
    319         memset((unsigned char *) context, 0, sizeof(*context));
    320     }
    321 
    322 }

    转载于:https://www.cnblogs.com/CPYER/p/3276926.html

    展开全文
  • 1.不依赖于Window平台库的C++库源代码 2.针对Windows平台跨语言变成的VC6编译的标准DLL
  • MD5纯C实现,付详细注释

    热门讨论 2011-06-30 15:41:32
    md5加密算法c实现,完整源代码。 压缩包包括完整vc6工程文件,使用的时候,只要把MD5.H和md5.c复制就可以了。 详见:http://blog.csdn.net/coder0621/archive/2007/03/23/1539208.aspx
  • VC C++ 200种 加密算法

    热门讨论 2012-11-22 11:40:14
    1998/11/19 12:11 5,369 md5mac.cpp 1998/12/12 14:23 683 md5mac.h 1998/12/12 14:23 1,222 mdc.h 1998/11/24 21:26 1,565 misc.cpp 1998/12/12 14:23 6,121 misc.h 1998/12/29 23:53 4,134 modarith.h 1998/11/19 ...
  • DES,MD5,ZLIB算法源代码

    2009-09-17 10:03:25
    DES MD5 ZLIB 加密算法的VC++源代码,VC6代码
  •   Crypto++ Library is a free C++ class library of cryptographic schemes. 可以到下面的网址... 提供丰富的加密解密算法,包括:MD5,IDEA, Triple-DES,AES (Rijndael), RC6, MARS, Twofish, Serpe

     

    Crypto++ Library is a free C++ class library of cryptographic schemes.
    可以到下面的网址下载最新源代码:

    http://www.cryptopp.com/

     

    Crypto++ Library 是开源的、跨平台的C++, 提供丰富的加密解密算法,包括:MD5,IDEA, Triple-DES,AES (Rijndael), RC6, MARS, Twofish, Serpent, RSA, DSA, SHA-1, SHA-2 等等。

     

    支持的编译器如下:

      * MSVC 6.0 - 2010
      * GCC 3.3 - 4.5
      * C++Builder 2010
      * Intel C++ Compiler 9 - 11.1
      * Sun Studio 12u1, Express 11/08, Express 06/10

     

    ==============================

     

    这里简单说明一下使用 MSVC2008 对Crypto++进行编译使用的方法和注意事项, 希望对大家开始学习有帮助!

    下面一段的英文比较简单, 说明了Crypto++包含的工程情况, 以及使用注意事项, 一看就清楚:

     

    On Windows, Crypto++ can be compiled into 3 forms: a static library
    including all algorithms, a DLL with only FIPS Approved algorithms, and
    a static library with only algorithms not in the DLL.

     

     

    To compile Crypto++ with MSVC, open the "cryptest.dsw" (for MSVC 6 and MSVC .NET
    2003) or "cryptest.sln" (for MSVC 2005 - 2010) workspace file and build one or
    more of the following projects:

     

    //用于生成包含所有算法的静态库

    cryptlib - a static libraryincluding all algorithms

     

    //用于生成仅包含FIPS作为标准的算法的dll和导入库

    cryptopp - This builds the DLL. Please note that if you wish to use Crypto++
      as a FIPS validated module, you must use a pre-built DLL that has undergone
      the FIPS validation process instead of building your own.
     

    //基于dll开发的例子程序
    dlltest - This builds a sample application that only uses the DLL.

     

    //基于cryptlib静态库开发的测试驱动程序

    cryptest Non-DLL-Import Configuration - This builds the full static library
      along with a full test driver.
     

    //基于dll 和不包含FIPS法静态库开发的测试驱动程序

     

     

    cryptest DLL-Import Configuration - This builds a static library containing
      only algorithms not in the DLL, along with a full test driver that uses
      both the DLL and the static library.

     

    To use the Crypto++ DLL in your application, #include "dll.h" before including
    any other Crypto++ header files, and place the DLL in the same directory as
    your .exe file. dll.h includes the line #pragma comment(lib, "cryptopp")
    so you don't have to explicitly list the import library in your project
    settings.

     

    To use a static library form of Crypto++, make the "cryptlib"
    project a dependency of your application project, or specify it as
    an additional library to link with in your project settings.
    In either case you should check the compiler options to
    make sure that the library and your application are using the same C++
    run-time libraries and calling conventions.

     

    -----------------

    名词解释:

    FIPS : Federal Information Processing Standards   (美国)联邦信息处理标准

     

     

     

     

     

    展开全文
  • 类库KYLib 2.0 for VC6

    2009-02-21 22:46:35
    编码相关函数 {CRC32 编码, Base64 编码, MD5 编码, 加密/解密编码} g. 线程类 {TThread, TKYThread, TKYRunThread等等} h. 文件类 {TFile, TKYDebugFile, TKYLogObj等等} i. ini文件类 {TIniFile, TMemIniFile...
  • 类库KYLib 3.1.0.0 for VC6

    2014-11-03 18:43:28
    MD5编码, 加密/解密编码等等} g. 线程相关类 {TThread, TKYThread, TKYRunThread, TKYAsynchRun, TKYTimer等等} h. 文件类 {TFile, TKYMapFile, TKYDebugFile, TKYLogObj等等} i. 文件表类 {TKYTable, ...
  • 类库KYLib 3.0.9.3 for VC6

    2014-04-22 10:28:58
    MD5编码, 加密/解密编码等等} g. 线程相关类 {TThread, TKYThread, TKYRunThread, TKYAsynchRun, TKYTimer等等} h. 文件类 {TFile, TKYMapFile, TKYDebugFile, TKYLogObj等等} i. 文件表类 {TKYTable, ...
  • 类库KYLib 2.0.8.4 for VC6

    2009-09-29 21:09:21
    编码相关函数 {CRC32 编码, Base64 编码, MD5 编码, 加密/解密编码} g. 线程类 {TThread, TKYThread, TKYRunThread等等} h. 文件类 {TFile, TKYDebugFile, TKYLogObj等等} i. ini文件类 {TIniFile, TMemIniFile...
  • 类库KYLib 2.0.9.0 for VC6

    2009-10-22 19:59:39
    编码相关函数 {CRC32 编码, Base64 编码, MD5 编码, 加密/解密编码} g. 线程类 {TThread, TKYThread, TKYRunThread等等} h. 文件类 {TFile, TKYDebugFile, TKYLogObj等等} i. ini文件类 {TIniFile, TMemIniFile...
  • 类库KYLib 2.0.8.1 for VC6

    2009-08-01 21:58:20
    编码相关函数 {CRC32 编码, Base64 编码, MD5 编码, 加密/解密编码} g. 线程类 {TThread, TKYThread, TKYRunThread等等} h. 文件类 {TFile, TKYDebugFile, TKYLogObj等等} i. ini文件类 {TIniFile, TMemIniFile...
  • 类库KYLib 3.0.0.0 for VC6

    2011-03-10 10:10:58
    编码相关函数 {Randomize, Random, Unicode/UTF8编码, CRC32编码, Base64编码, MD5编码, 加密/解密编码等等} g. 线程相关类 {TThread, TKYThread, TKYRunThread, TKYAsynchRun, TKYTimer等等} h. 文件类 {TFile, ...
  • 类库KYLib 2.1.3.1 for VC6

    2010-06-12 17:54:24
    编码相关函数 {Unicode/UTF8编码, CRC32编码, Base64编码, MD5编码, 加密/解密编码等等} g. 线程相关类 {TThread, TKYThread, TKYAsynchRun, TKYRunThread, TKYTimer等等} h. 文件类 {TFile, TKYDebugFile, ...
  • 类库KYLib 2.1.7.0 for VC6

    2010-10-17 09:53:01
    编码相关函数 {Randomize, Random, Unicode/UTF8编码, CRC32编码, Base64编码, MD5编码, 加密/解密编码等等} g. 线程相关类 {TThread, TKYThread, TKYRunThread, TKYAsynchRun, TKYTimer等等} h. 文件类 {TFile, ...
  • 类库KYLib 2.1.1.0 for VC6

    2010-02-01 21:41:18
    编码相关函数 {Unicode/UTF8编码, CRC32编码, Base64编码, MD5编码, 加密/解密编码} g. 线程相关类 {TThread, TKYThread, TKYAsynchRun, TKYRunThread, TKYTimer等等} h. 文件类 {TFile, TKYDebugFile, TKYLogObj...
  • 类库KYLib 3.0.2.7 for VC6

    2011-10-27 13:38:45
    MD5编码, 加密/解密编码等等} g. 线程相关类 {TThread, TKYThread, TKYRunThread, TKYAsynchRun, TKYTimer等等} h. 文件类 {TFile, TKYMapFile, TKYDebugFile, TKYLogObj等等} i. 文件表类 {TKYTable, ...
  • 类库KYLib 3.0.2.1 for VC6

    2011-06-28 10:12:07
    MD5编码, 加密/解密编码等等} g. 线程相关类 {TThread, TKYThread, TKYRunThread, TKYAsynchRun, TKYTimer等等} h. 文件类 {TFile, TKYMapFile, TKYDebugFile, TKYLogObj等等} i. 文件表类 {TKYTable, ...
  • 采用SMGP协议的短消息发送中心. 其中身份验证过程中需要一个md5 hash的加密过程.由于采用的是vc6开发.没有直接的库调用.所以baidu了一段代码. 测试一下,还真好用,输入一个字符串能得到一个32位的字符串 ....

     最近在做的一个项目需要给客户群体发送短消息.采用SMGP协议的短消息发送中心.

    其中身份验证过程中需要一个md5 hash的加密过程.由于采用的是vc6开发.没有直接的库调用.所以baidu了一段代码.

    测试一下,还真好用,输入一个字符串能得到一个32位的字符串 .16位的字符串是这个32位字符串从第8位开始的16位的子串.

    代码都是抄袭的,只是我加了个获得16位结果的方法.

    ----- md5.h-------------

    #ifndef _MD5_H_
    #define _MD5_H_


    char* MD5String32( char* string );
    char* MD5String16( char* string );

    bool MD5Check32( char *md5string, char* string );

    #endif //_MD5_H_

     

    ---- md5.cpp-----------

    #include "stdafx.h"
    #include<stdio.h>
    #include<stdlib.h>
    #include<string.h>
    #include<math.h>
    #include<ctype.h>
    #include "md5.h"

    /* POINTER defines a generic pointer type */
    typedef unsigned char *POINTER;

    /* UINT2 defines a two byte word */
    typedef unsigned short int UINT2;

    /* UINT4 defines a four byte word */
    typedef unsigned long int UINT4;

    #define PROTO_LIST(list) list

    /* MD5 context. */
    typedef struct _MD5_CTX
    {
        UINT4 state[4]; /* state (ABCD) */
        UINT4 count[2]; /* number of bits, modulo 2^64 (lsb first) */
        unsigned char buffer[64]; /* input buffer */
    } MD5_CTX;

    /* Constants for MD5Transform routine.
    */
    #define S11 7
    #define S12 12
    #define S13 17
    #define S14 22
    #define S21 5
    #define S22 9
    #define S23 14
    #define S24 20
    #define S31 4
    #define S32 11
    #define S33 16
    #define S34 23
    #define S41 6
    #define S42 10
    #define S43 15
    #define S44 21

    static unsigned char PADDING[64] = {
        0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
    };

    /* F, G, H and I are basic MD5 functions.
    */
    #define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
    #define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
    #define H(x, y, z) ((x) ^ (y) ^ (z))
    #define I(x, y, z) ((y) ^ ((x) | (~z)))

    /* ROTATE_LEFT rotates x left n bits.
    */
    #define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))

    /* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
    Rotation is separate from addition to prevent recomputation.
    */
    #define FF(a, b, c, d, x, s, ac) { /
        (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac);/
        (a) = ROTATE_LEFT ((a), (s)); /
        (a) += (b); /
        }
    #define GG(a, b, c, d, x, s, ac) { /
        (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); /
        (a) = ROTATE_LEFT ((a), (s)); /
        (a) += (b); /
        }
    #define HH(a, b, c, d, x, s, ac) { /
        (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); /
        (a) = ROTATE_LEFT ((a), (s)); /
        (a) += (b); /
        }
    #define II(a, b, c, d, x, s, ac) { /
        (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); /
        (a) = ROTATE_LEFT ((a), (s)); /
        (a) += (b); /
        }

    #define TEST_BLOCK_LEN 1000
    #define TEST_BLOCK_COUNT 1000

    static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
    static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
    static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));
    static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
    static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
    static void MD5Init PROTO_LIST ((MD5_CTX *));
    static void MD5Update PROTO_LIST ((MD5_CTX *, unsigned char *, unsigned int));
    static void MD5Final PROTO_LIST ((unsigned char [16], MD5_CTX *));
    static void MDTimeTrial PROTO_LIST ((void));
    static void StringAddOne PROTO_LIST ((char *));
    static void Encode PROTO_LIST ((unsigned char *, UINT4 *, unsigned int));
    static void Decode PROTO_LIST ((UINT4 *, unsigned char *, unsigned int));

    /* MD5 initialization. Begins an MD5 operation, writing a new context.
    */
    static void MD5Init( MD5_CTX *context )
    {
        context->count[0] = context->count[1] = 0;
        /* Load magic initialization constants.
        */
        context->state[0] = 0x67452301;
        context->state[1] = 0xefcdab89;
        context->state[2] = 0x98badcfe;
        context->state[3] = 0x10325476;
    }

    /* MD5 block update operation. Continues an MD5 message-digest
    operation, processing another message block, and updating the
    context.
    */
    static void MD5Update(
                   MD5_CTX *context,        /* context */
                   unsigned char *input,    /* input block */
                   unsigned int inputLen    /* length of input block */
                   )
    {
        unsigned int i, index, partLen;
       
        /* Compute number of bytes mod 64 */
        index = (unsigned int)((context->count[0] >> 3) & 0x3F);
       
        /* Update number of bits */
        if ((context->count[0] += ((UINT4)inputLen << 3))
            < ((UINT4)inputLen << 3))
            context->count[1]++;
        context->count[1] += ((UINT4)inputLen >> 29);
       
        partLen = 64 - index;
       
        /* Transform as many times as possible.
        */
        if (inputLen >= partLen) {
            MD5_memcpy
                ((POINTER)&context->buffer[index], (POINTER)input, partLen);
            MD5Transform (context->state, context->buffer);
           
            for (i = partLen; i + 63 < inputLen; i += 64)
                MD5Transform (context->state, &input[i]);
           
            index = 0;
        }
        else
            i = 0;
       
        /* Buffer remaining input */
        MD5_memcpy
            ((POINTER)&context->buffer[index], (POINTER)&input[i],
            inputLen-i);
    }

    /* MD5 finalization. Ends an MD5 message-digest operation, writing the
    the message digest and zeroizing the context.
    */
    static void MD5Final(
                  unsigned char digest[16], /* message digest */
                  MD5_CTX *context          /* context */
                  )
    {
        unsigned char bits[8];
        unsigned int index, padLen;
       
        /* Save number of bits */
        Encode (bits, context->count, 8);
       
        /* Pad out to 56 mod 64.
        */
        index = (unsigned int)((context->count[0] >> 3) & 0x3f);
        padLen = (index < 56) ? (56 - index) : (120 - index);
        MD5Update (context, PADDING, padLen);
       
        /* Append length (before padding) */
        MD5Update (context, bits, 8);
       
        /* Store state in digest */
        Encode (digest, context->state, 16);
       
        /* Zeroize sensitive information.
        */
        MD5_memset ((POINTER)context, 0, sizeof (*context));
    }

    /* MD5 basic transformation. Transforms state based on block.
    */
    static void MD5Transform(
                             UINT4 state[4],
                             unsigned char block[64]
                             )
    {
        UINT4 a = state[0], b = state[1], c = state[2], d = state[3], x[16];
       
        Decode (x, block, 64);
       
        /* Round 1 */
        FF (a, b, c, d, x[ 0], S11, 0xd76aa478); /* 1 */
        FF (d, a, b, c, x[ 1], S12, 0xe8c7b756); /* 2 */
        FF (c, d, a, b, x[ 2], S13, 0x242070db); /* 3 */
        FF (b, c, d, a, x[ 3], S14, 0xc1bdceee); /* 4 */
        FF (a, b, c, d, x[ 4], S11, 0xf57c0faf); /* 5 */
        FF (d, a, b, c, x[ 5], S12, 0x4787c62a); /* 6 */
        FF (c, d, a, b, x[ 6], S13, 0xa8304613); /* 7 */
        FF (b, c, d, a, x[ 7], S14, 0xfd469501); /* 8 */
        FF (a, b, c, d, x[ 8], S11, 0x698098d8); /* 9 */
        FF (d, a, b, c, x[ 9], S12, 0x8b44f7af); /* 10 */
        FF (c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */
        FF (b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */
        FF (a, b, c, d, x[12], S11, 0x6b901122); /* 13 */
        FF (d, a, b, c, x[13], S12, 0xfd987193); /* 14 */
        FF (c, d, a, b, x[14], S13, 0xa679438e); /* 15 */
        FF (b, c, d, a, x[15], S14, 0x49b40821); /* 16 */
       
        /* Round 2 */
        GG (a, b, c, d, x[ 1], S21, 0xf61e2562); /* 17 */
        GG (d, a, b, c, x[ 6], S22, 0xc040b340); /* 18 */
        GG (c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */
        GG (b, c, d, a, x[ 0], S24, 0xe9b6c7aa); /* 20 */
        GG (a, b, c, d, x[ 5], S21, 0xd62f105d); /* 21 */
        GG (d, a, b, c, x[10], S22, 0x2441453); /* 22 */
        GG (c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */
        GG (b, c, d, a, x[ 4], S24, 0xe7d3fbc8); /* 24 */
        GG (a, b, c, d, x[ 9], S21, 0x21e1cde6); /* 25 */
        GG (d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */
        GG (c, d, a, b, x[ 3], S23, 0xf4d50d87); /* 27 */
        GG (b, c, d, a, x[ 8], S24, 0x455a14ed); /* 28 */
        GG (a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */
        GG (d, a, b, c, x[ 2], S22, 0xfcefa3f8); /* 30 */
        GG (c, d, a, b, x[ 7], S23, 0x676f02d9); /* 31 */
        GG (b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */
       
        /* Round 3 */
        HH (a, b, c, d, x[ 5], S31, 0xfffa3942); /* 33 */
        HH (d, a, b, c, x[ 8], S32, 0x8771f681); /* 34 */
        HH (c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */
        HH (b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */
        HH (a, b, c, d, x[ 1], S31, 0xa4beea44); /* 37 */
        HH (d, a, b, c, x[ 4], S32, 0x4bdecfa9); /* 38 */
        HH (c, d, a, b, x[ 7], S33, 0xf6bb4b60); /* 39 */
        HH (b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */
        HH (a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */
        HH (d, a, b, c, x[ 0], S32, 0xeaa127fa); /* 42 */
        HH (c, d, a, b, x[ 3], S33, 0xd4ef3085); /* 43 */
        HH (b, c, d, a, x[ 6], S34, 0x4881d05); /* 44 */
        HH (a, b, c, d, x[ 9], S31, 0xd9d4d039); /* 45 */
        HH (d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */
        HH (c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */
        HH (b, c, d, a, x[ 2], S34, 0xc4ac5665); /* 48 */
       
        /* Round 4 */
        II (a, b, c, d, x[ 0], S41, 0xf4292244); /* 49 */
        II (d, a, b, c, x[ 7], S42, 0x432aff97); /* 50 */
        II (c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */
        II (b, c, d, a, x[ 5], S44, 0xfc93a039); /* 52 */
        II (a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */
        II (d, a, b, c, x[ 3], S42, 0x8f0ccc92); /* 54 */
        II (c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */
        II (b, c, d, a, x[ 1], S44, 0x85845dd1); /* 56 */
        II (a, b, c, d, x[ 8], S41, 0x6fa87e4f); /* 57 */
        II (d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */
        II (c, d, a, b, x[ 6], S43, 0xa3014314); /* 59 */
        II (b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */
        II (a, b, c, d, x[ 4], S41, 0xf7537e82); /* 61 */
        II (d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */
        II (c, d, a, b, x[ 2], S43, 0x2ad7d2bb); /* 63 */
        II (b, c, d, a, x[ 9], S44, 0xeb86d391); /* 64 */
       
        state[0] += a;
        state[1] += b;
        state[2] += c;
        state[3] += d;
       
        /* Zeroize sensitive information.
        */
        MD5_memset ((POINTER)x, 0, sizeof (x));
    }

    /* Encodes input (UINT4) into output (unsigned char). Assumes len is
    a multiple of 4.
    */
    static void Encode(
                       unsigned char *output,
                       UINT4 *input,
                       unsigned int len
                       )
    {
        unsigned int i, j;
       
        for (i = 0, j = 0; j < len; i++, j += 4) {
            output[j] = (unsigned char)(input[i] & 0xff);
            output[j+1] = (unsigned char)((input[i] >> 8) & 0xff);
            output[j+2] = (unsigned char)((input[i] >> 16) & 0xff);
            output[j+3] = (unsigned char)((input[i] >> 24) & 0xff);
        }
    }

    /* Decodes input (unsigned char) into output (UINT4). Assumes len is
    a multiple of 4.
    */
    static void Decode(
                       UINT4 *output,
                       unsigned char *input,
                       unsigned int len
                       )
    {
        unsigned int i, j;
       
        for (i = 0, j = 0; j < len; i++, j += 4)
            output[i] = ((UINT4)input[j]) | (((UINT4)input[j+1]) << 8) |
            (((UINT4)input[j+2]) << 16) | (((UINT4)input[j+3]) << 24);
    }

    /* Note: Replace "for loop" with standard memcpy if possible.
    */
    static void MD5_memcpy(
                           POINTER output,
                           POINTER input,
                           unsigned int len
                           )
    {
        unsigned int i;
       
        for (i = 0; i < len; i++)
            output[i] = input[i];
    }

    /* Note: Replace "for loop" with standard memset if possible.
    */
    static void MD5_memset(
                           POINTER output,
                           int value,
                           unsigned int len
                           )
    {
        unsigned int i;
       
        for (i = 0; i < len; i++)
            ((char *)output)[i] = (char)value;
    }

    /* Digests a string and prints the result.
    */
    char* MD5String32( char *string )
    {
        MD5_CTX context;
        unsigned char digest[16];
        char output1[33];
        static char output[33]={""};
        unsigned int len = strlen (string);
        int i;

        MD5Init( &context);
        MD5Update( &context, (unsigned char*)string, len );
        MD5Final( digest, &context );
       
        for (i = 0; i < 16; i++)
        {
            sprintf(&(output1[2*i]),"%02x",(unsigned char)digest[i]);
            sprintf(&(output1[2*i+1]),"%02x",(unsigned char)(digest[i]<<4));
        }
        for(i=0;i<32;i++)
        {
            output[i]=output1[i];
        }
        return output;
    }

    char* MD5String16( char *string )
    {
        MD5_CTX context;
        unsigned char digest[16];
        char output1[33];
        static char output[16]={""};
        unsigned int len = strlen (string);
        int i;

        MD5Init( &context);
        MD5Update( &context, (unsigned char*)string, len );
        MD5Final( digest, &context );
       
        for (i = 0; i < 16; i++)
        {
            sprintf(&(output1[2*i]),"%02x",(unsigned char)digest[i]);
            sprintf(&(output1[2*i+1]),"%02x",(unsigned char)(digest[i]<<4));
        }
        for(i=0;i<16;i++)
        {
            output[i]=output1[i+8];
        }
        return output;
    }

    /* get the string add one.
    */
    static void StringAddOne( char * orstring )
    {
        unsigned int len;
        int i,n;

        len = strlen(orstring);
        n = len - 1;
        for(i = n; i >= 0; i--)
        {
            if(orstring[i]=='9')
            {
                orstring[i] = 'A';
                break;
            }
            else if(orstring[i]=='Z')
            {
                orstring[i]='a';
                break;
            }
            else if(orstring[i]=='z')
            {
                orstring[i]='0';
                continue;
            }
            else
                orstring[i] += 1;
            break;
        }
    }

    /* check the md5 strings one by one,get the password.
    */
    bool MD5Check32( char *md5string, char* string )
    {
        return strcmp( md5string, MD5String32( string ) ) == 0;
    }

     

     

    不做解释拿来用就OK了.

    步子迈大了,容易扯到蛋~~~(让子弹飞里汤师爷的一句台词)

    展开全文
  • 标准算法模块是集DES、3DES、AES、RSA、MD5、BlowFish、TEA、RC6等标准算法为一体的算法包,同时在模块中使用了Anti-Debug和程序自校验功能(涉及到软件的加壳和CRC32)、软件使用次数限制,更好的保护您的软件。...
  • 1,公钥私钥使用的是PEM格式,可使用网络工具互转xml格式 2,加密解密使用的是文件名,可...5,注意VC6.0中编译的使用的环境 MDd 还是MD 工程环境和静态库环境一直 6,本工程使用的库为:cryptopp560,可下载最新版本编译
  • 共享软件加密算法库

    2006-03-16 00:00:00
    一款用于共享软件加密的动态链接库文件,包含了获取硬盘物理序列号及BlowFish、MD5、SHA512、RIPEMD160、Secret16、MD5FileCheck、CRCFileCheck等多种强大加密算法,可以非常方便的用于软件的各类加密需求。支持VC/...
  • 加密算法模块

    2004-07-19 00:00:00
    标准算法模块是集DES、3DES、AES、RSA、MD5、BlowFish、TEA、RC6等标准算法为一体的算法包,同时在模块中使用了Anti-Debug和程序自校验功能(涉及到软件的加壳和CRC32),更好的保护您的软件。在模块中作者给出了每...
  • vc源代码合集0951.rar

    热门讨论 2012-06-13 10:25:18
    2012-06-12 12:51 1,826,942 md5加密算法源代码.rar 2012-06-12 11:48 79,221 MFC音乐播放器(滑块控制音量).zip 2012-06-12 13:01 74,769 MyQQ-VC开发的局域网通信程序.rar 2012-06-12 12:18 1,154 N个数中1的个数....

空空如也

空空如也

1 2 3 4 5
收藏数 91
精华内容 36
关键字:

md5加密vc6