關於 MD5演算法的類

2021-04-13 05:06:45 字數 2742 閱讀 7242

實現md5演算法的封裝類

//md5.h

#ifndef _lgy_md5_h

#define _lgy_md5_h

/* md5 class. */

class md5_ctx ;

#endif 

//md5.cpp

#include "stdafx.h"

#include "md5.h"

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

/* md5 initialization. begins an md5 operation, writing a new context.

*/md5_ctx::md5_ctx()

md5_ctx::~md5_ctx()

void md5_ctx::md5init ();}

/* md5 block update operation. continues an md5 message-digest

operation, processing another message block, and updating the

context.

*/void md5_ctx::md5update (unsigned char *input,unsigned int inputlen)

else

i = 0;

/* buffer remaining input */

md5_memcpy ((unsigned char*)&this->buffer[index], (unsigned char*)&input[i], inputlen-i);

}/* md5 basic transformation. transforms state based on block.

*/void md5_ctx::md5transform (unsigned long int state[4], unsigned char block[64])

/* encodes input (unsigned long int) into output (unsigned char). assumes len is

a multiple of 4.

*/void md5_ctx::encode (unsigned char *output, unsigned long int *input,unsigned int len)

}/* decodes input (unsigned char) into output (unsigned long int). assumes len is

a multiple of 4.

*/void md5_ctx::decode (unsigned long int *output, unsigned char *input, unsigned int len)

/* note: replace "for loop" with standard memcpy if possible.

*/void md5_ctx::md5_memcpy (unsigned char* output, unsigned char* input,unsigned int len)

/* note: replace "for loop" with standard memset if possible.

*/void md5_ctx::md5_memset (unsigned char* output,int value,unsigned int len)

關於MD5加密

前言 任何以明文方式儲存使用者密碼的行為都是耍流氓。md5作為一種單項加密方式,常用在資料脫敏和軟體數字簽名等方面。以下是介紹正文 md5的全稱是message digest algorithm 5 資訊 摘要演算法 在90年代初由mit laboratory for computer scienc...

關於MD5加密

md5 tanajiya.tar.gz 0ca175b9c0f726a831d895e269332461 這就是tanajiya.tar.gz檔案的數字簽名。md5將整個檔案當作乙個大文字資訊,通過其不可逆的字串變換演算法,產生了這個唯一的md5資訊摘要。為了讓讀者朋友對md5的應用有個直觀的認識,...

關於md5加密

說明 隨著網路發展的越來越廣泛,網上業務越來越流行,使用者的隱私資訊安全性也越來越重要!加密的方式有很多種 目前比較受程式設計師推崇的還是md5加密!md5加密的原理 對任何資訊進行處理生成唯一的128位雜湊表,也就是32個字元 使用步驟 可以直接使用xcode提供的加密也可以在文件中匯入第三方的m...