.h檔案**。
.cpp檔案**。
實現,可以在應用的.cpp檔案內打包成函式tokey。如下:
只學習了將密碼轉換成秘鑰的過程,下面的md5還包括其他的功能,以後再學習。
#ifndef md5_h
#define md5_h
#include #include /* type define */
typedef unsigned char byte;
typedef unsigned int uint32;
using std::string;
using std::ifstream;
#pragma once
/* md5 declaration. */
class md5 ;
};#endif /*md5_h*/
#include "stdafx.h"
#include "mymd5.h"
#include "stdafx.h"
#include "string.h"
const string md5_key = "wow";
using namespace std;
/* 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
/* 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)
#define gg(a, b, c, d, x, s, ac)
#define hh(a, b, c, d, x, s, ac)
#define ii(a, b, c, d, x, s, ac)
const byte md5::padding[64] = ;
const char md5::hex[16] = ;
/* default construct. */
md5::md5()
/* construct a md5 object with a input buffer. */
md5::md5(const void* input, size_t length)
/* construct a md5 object with a string. */
md5::md5(const string& str)
/* construct a md5 object with a file. */
md5::md5(ifstream& in)
/* return the message-digest */
const byte* md5::digest()
return _digest;
}/* reset the calculate state */
void md5::reset()
/* updating the context with a input buffer. */
void md5::update(const void* input, size_t length)
/* updating the context with a string. */
void md5::update(const string& str)
/* updating the context with a file. */
void md5::update(ifstream& in)
std::streamsize length;
char buffer[buffer_size];
while (!in.eof())
} in.close();
}/* md5 block update operation. continues an md5 message-digest
operation, processing another message block, and updating the
context.
*/void md5::update(const byte* input, size_t length)
_count[1] += ((uint32)length >> 29);
partlen = 64 - index;
/* transform as many times as possible. */
if (length >= partlen)
index = 0;
} else
/* buffer remaining input */
memcpy(&_buffer[index], &input[i], length - i);
}/* md5 finalization. ends an md5 message-_digest operation, writing the
the message _digest and zeroizing the context.
*/void md5::final()
/* md5 basic transformation. transforms _state based on block. */
void md5::transform(const byte block[64])
/* encodes input (ulong) into output (byte). assumes length is
a multiple of 4.
*/void md5::encode(const uint32* input, byte* output, size_t length)
}/* decodes input (byte) into output (ulong). assumes length is
a multiple of 4.
*/void md5::decode(const byte* input, uint32* output, size_t length)
}/* convert byte array to hex string. */
string md5::bytestohexstring(const byte* input, size_t length)
return str;
}/* convert digest to string value */
string md5::tostring()
string md5::tomd5(const string& str) //md5加密,其中金鑰key=xyf,金鑰需加在加密之前
//將密碼加密為md5形式
cstring passwordorkey::tokey( cstring password)
C MD5加密與解密
using system.security.cryptography using system.io using system.text md5解密 public string md5decrypt string ptodecrypt,string skey des.key asciiencodin...
C MD5加密方法
using system.security.cryptography md5加密函式 public string md5 string str ms的help using system using system.security.cryptography using system.text clas...
C MD5加密演算法
以前收集的加密演算法 md5加密演算法 呼叫方法md5encode.encrypt smessage 單向加密,沒有解密演算法 適用於短內容加密,加密後不需要再解密的內容 public class md5encode else else return lshift else if convert.t...