• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ MD5_Init函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中MD5_Init函数的典型用法代码示例。如果您正苦于以下问题:C++ MD5_Init函数的具体用法?C++ MD5_Init怎么用?C++ MD5_Init使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了MD5_Init函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: cache_mng_get_md5

// we can only get md5 of an object containing 1 range
// XXX: move code to separate thread
gboolean cache_mng_get_md5 (CacheMng *cmng, fuse_ino_t ino, gchar **md5str)
{
    struct _CacheEntry *entry;
    unsigned char digest[MD5_DIGEST_LENGTH];
    MD5_CTX md5ctx;
    ssize_t bytes;
    unsigned char data[1024];
    char path[PATH_MAX];
    size_t i;
    gchar *out;
    FILE *in;

    entry = g_hash_table_lookup (cmng->h_entries, GUINT_TO_POINTER (ino));
    if (!entry)
        return FALSE;
    
    if (range_count (entry->avail_range) != 1) {
        LOG_debug (CMNG_LOG, INO_H"Entry contains more than 1 range, can't take MD5 sum of such object !", INO_T (ino));
        return FALSE;
    }

    cache_mng_file_name (cmng, path, sizeof (path), ino);
    in = fopen (path, "rb");
    if (in == NULL) {
        LOG_debug (CMNG_LOG, INO_H"Can't open file for reading: %s", INO_T (ino), path);
        return FALSE;
    }

    MD5_Init (&md5ctx);
    while ((bytes = fread (data, 1, 1024, in)) != 0)
        MD5_Update (&md5ctx, data, bytes);
    MD5_Final (digest, &md5ctx);
    fclose (in);

    out = g_malloc (33);
    for (i = 0; i < 16; ++i)
        sprintf (&out[i*2], "%02x", (unsigned int)digest[i]);

    *md5str = out;

    return TRUE;
}
开发者ID:bfleischer,项目名称:riofs,代码行数:44,代码来源:cache_mng.c


示例2: lua_util_md5

static int lua_util_md5(lua_State* L)
{
    const char* path=lua_tostring(L,1);
    if(!path)
        lua_pushnil(L);
    else
    {
        FILE* fp=fopen(path,"rb");
        if(!fp)
            lua_pushnil(L);
        else
        {
            MD5_CTX ctx;
            MD5_Init(&ctx);

            {
                char tmp[512];
                size_t n;
                while((n=fread(tmp,1,sizeof(tmp),fp))>0)
                    MD5_Update(&ctx,(unsigned char*)tmp,n);
            }

            fclose(fp);

            unsigned char tmp[16];
            MD5_Final(tmp,&ctx);

            char buf[sizeof(tmp)*2];

            static const char hex[]="0123456789abcdef";
            for(int i=0,j=0;i<sizeof(tmp);i++)
            {
                buf[j++]=hex[(tmp[i]>>4)&0x0f];
                buf[j++]=hex[tmp[i]&0x0f];
            }

            lua_pushlstring(L,buf,sizeof(buf));
        }
    }

    return 1;
}
开发者ID:schidler,项目名称:flyzjhz-rt-n56u,代码行数:42,代码来源:luaxlib.cpp


示例3: get_part_cksum

static int get_part_cksum(struct file *f, FILE **fp)
{
	MD5_CTX md5;
	int got=0;
	static char buf[PART_CHUNK];
	unsigned char checksum[MD5_DIGEST_LENGTH+1];

	if(*fp) fseek(*fp, 0, SEEK_SET);
	else if(!(*fp=open_file(f)))
	{
		f->part_cksum=0;
		return 0;
	}

	if(!MD5_Init(&md5))
	{
		logp("MD5_Init() failed\n");
		return -1;
	}

	got=fread(buf, 1, PART_CHUNK, *fp);

	if(!MD5_Update(&md5, buf, got))
	{
		logp("MD5_Update() failed\n");
		return -1;
	}

	if(!MD5_Final(checksum, &md5))
	{
		logp("MD5_Final() failed\n");
		return -1;
	}

	memcpy(&(f->part_cksum), checksum, sizeof(unsigned));

	// Try for a bit of efficiency - no need to calculate the full checksum
	// again if we already read the whole file.
	if(got<PART_CHUNK) f->full_cksum=f->part_cksum;

	return 0;
}
开发者ID:tcheneau,项目名称:burp,代码行数:42,代码来源:bedup.c


示例4: calc_hash

void calc_hash(const char *filename)
{
    int n;
    unsigned char data[BUFFSIZE];
    FILE *file = fopen(filename, "rb");
    if (file == NULL) {
        fprintf(stderr, "'%s' ", filename);
        perror("文件打开失败");
        return;
    }

    unsigned char md5[MD5_DIGEST_LENGTH];
    MD5_CTX md5_c;
    unsigned char sha1[SHA_DIGEST_LENGTH];
    SHA_CTX sha1_c;
    unsigned char sha512[SHA_DIGEST_LENGTH];
    SHA512_CTX sha512_c;

    MD5_Init(&md5_c);
    SHA1_Init(&sha1_c);
    SHA512_Init(&sha512_c);
    while ((n = fread(data, 1, BUFFSIZE, file)) != 0) {
        MD5_Update(&md5_c, data, n);
        SHA1_Update(&sha1_c, data, n);
        SHA512_Update(&sha512_c, data, n);
    }
    MD5_Final(md5, &md5_c);
    SHA1_Final(sha1, &sha1_c);
    SHA512_Final(sha512, &sha512_c);

    int i;
    printf("%s", filename);
    printf("\n%8s: ", "MD5");
    for (i = 0; i < MD5_DIGEST_LENGTH; i++) printf("%02x", md5[i]);
    printf("\n%8s: ", "SHA1");
    for (i = 0; i < SHA_DIGEST_LENGTH; i++) printf("%02x", sha1[i]);
    printf("\n%8s: ", "SHA512");
    for (i = 0; i < SHA_DIGEST_LENGTH; i++) printf("%02x", sha512[i]);
    printf("\n");

    fclose(file);
}
开发者ID:kingfree,项目名称:haut,代码行数:42,代码来源:md5.c


示例5: do_update

		int32_t do_update(const std::string& _file, const std::string& _md5, const update_params& _params)
		{
			http_request_simple request(core::proxy_settings(), _params.is_stoped_);
			request.set_url(get_update_server() + _file);
            request.set_need_log(false);
			if (!request.get())
				return -1;

			int32_t http_code = (uint32_t)request.get_response_code();
			if (http_code != 200)
				return -1;

			auto response = request.get_response();

			if (!response->available())
				return -1;

			int32_t size = response->available();

			MD5_CTX md5handler;
			unsigned char md5digest[MD5_DIGEST_LENGTH];

			MD5_Init(&md5handler);
			MD5_Update(&md5handler, response->read(size), size);
			MD5_Final(md5digest,&md5handler);

			char buffer[100];
			std::string md5;

			for (int32_t i = 0; i < MD5_DIGEST_LENGTH; i++)
			{
				sprintf(buffer, "%02x", md5digest[i]);
				md5 += buffer;
			}
		
			if (md5 != _md5)
				return -1;

			response->reset_out();

			return run_installer(*response);
		}
开发者ID:13W,项目名称:icq-desktop,代码行数:42,代码来源:updater.cpp


示例6: rsync_nextblock

/* Get the next rsync block of a file. */
int
rsync_nextblock(struct rsyncfile *rf)
{
	MD5_CTX ctx;
	size_t blocksize;

	if (rf->blockptr >= rf->end)
		return (0);
	blocksize = min((size_t)(rf->end - rf->blockptr), rf->blocksize);
	/* Calculate MD5 of the block. */
	MD5_Init(&ctx);
	MD5_Update(&ctx, rf->blockptr, blocksize);
	MD5_End(rf->blockmd5, &ctx);

	rf->rsum = rsync_rollsum(rf->blockptr, blocksize);
	snprintf(rf->rsumstr, RSUM_SIZE, "%x", rf->rsum);
	rf->blocknum++;
	rf->blockptr += blocksize;
	return (1);
}
开发者ID:AhmadTux,项目名称:freebsd,代码行数:21,代码来源:rsyncfile.c


示例7: tc_digest

std::string tc_digest(
	const char *algo,
	const char *ibytes,
	uint32_t nibytes)
{
	std::string ret("");
	if (algo && !strcmp(algo, "md5")) {
		uint8_t obytes[MD5_DIGEST_LENGTH];
		memset(obytes, 0, MD5_DIGEST_LENGTH);
		MD5_CTX ctx;
		MD5_Init(&ctx);
		MD5_Update(&ctx, ibytes, nibytes);
		MD5_Final(obytes, &ctx);
		char ret_cstr[2*MD5_DIGEST_LENGTH+1];
		for(uint32_t i=0; i < MD5_DIGEST_LENGTH; i++)
			sprintf(ret_cstr+2*i, "%02x", obytes[i]);
		ret = ret_cstr;
	}
	return ret;
}
开发者ID:AltCoinsLand,项目名称:Truthcoin,代码行数:20,代码来源:tc_data.cpp


示例8: blob_set_path_hash

void blob_set_path_hash(blob_t *blob, const uint8_t *data, size_t size)
{
    uint8_t hash[16];
    char path[256];
    char *p;

    MD5_CTX ctx;
    MD5_Init(&ctx);
    MD5_Update(&ctx, data, size);
    MD5_Final(hash, &ctx);

    strncpy(path, "crypto/", sizeof(path));
    p = strrchr(path, '/') + 1;
    for (size_t i = 0; i < sizeof(hash); i++) {
        snprintf(p, 3, "%02X", hash[i]);
        p += 2;
    }
    strncpy(p, ".bin", sizeof(path) - (p - &path[0]));
    blob_set_path(blob, path);
}
开发者ID:qiuhuahui1,项目名称:orbital,代码行数:20,代码来源:blob.c


示例9: calculate_md5

static int calculate_md5(char *str, const char *path) {
    FILE *fd;
    fd = fopen(path, "r");
    if (fd != NULL) {
        MD5_CTX c;
        size_t i;
        static unsigned char buf[BUFSIZE];
        unsigned char md5dig[MD5_DIGEST_LENGTH];
        MD5_Init(&c);
        while ((i = fread(buf, 1, BUFSIZE, fd)) > 0)
            MD5_Update(&c, buf, i);
        MD5_Final(&(md5dig[0]), &c);
        fclose(fd);
        to_md5_hash(str, md5dig);
    } else {
       return 1;
    }

    return 0;
}
开发者ID:APAR1992,项目名称:cwm_recovery_dual_language-1,代码行数:20,代码来源:nandroid_md5.c


示例10: lua_md5

static int lua_md5(lua_State* L)
{
    size_t l=0;

    const char* s=luaL_checklstring(L,1,&l);

    MD5_CTX ctx;
    MD5_Init(&ctx);
    MD5_Update(&ctx,(unsigned char*)s,l);

    unsigned char md[16];
    MD5_Final(md,&ctx);

    char buf[sizeof(md)*2];
    to_hex(md,buf,sizeof(md));
 
    lua_pushlstring(L,buf,sizeof(buf));

    return 1;
}
开发者ID:everaldoglima,项目名称:luasp,代码行数:20,代码来源:luamoz.cpp


示例11: MD5_Init

static char *md5_fd(int fd)
{
    MD5_CTX ctx;
    unsigned char buf[BUFSIZ], output[16];
    ssize_t n;

    MD5_Init(&ctx);

    while ((n = read(fd, buf, sizeof(buf))) > 0 || errno == EINTR) {
        if (n < 0)
            continue;
        MD5_Update(&ctx, buf, n);
    }

    if (n < 0)
        return NULL;

    MD5_Final(output, &ctx);
    return hex_representation(output, 16);
}
开发者ID:prodigeni,项目名称:repose,代码行数:20,代码来源:util.c


示例12: md5_identity

char * md5_identity(void *data, int len)
{
    unsigned char hash[16];
    char* result;
    int ptr,i;

    result = (char*)malloc(sizeof(char)*512);
    memset(result, 0, sizeof(result));
    MD5_CTX ctx;
    MD5_Init(&ctx);
    MD5_Update(&ctx,(char*)data,len);
    MD5_Final(hash,&ctx);

    ptr = 0;
    for(i=0;i<16;i++)
    {
        ptr += sprintf(result+ptr, "%02x", hash[i]);
    }
    return result;
}
开发者ID:Wizmann,项目名称:Utils,代码行数:20,代码来源:hdd_identity.c


示例13: md5sum

string md5sum(const char * str, int len)
{
	int n;
    MD5_CTX ctx;
    char buf[SLICECAP];
    unsigned char out[MD5_DIGEST_LENGTH];
    string md5str;

	MD5_Init(&ctx);
	MD5_Update(&ctx, str, len);
    MD5_Final(out, &ctx);

    for(n = 0; n< MD5_DIGEST_LENGTH; n++)
	{
		snprintf(buf, SLICECAP, "%02x", out[n]);
		md5str += buf;
	}

    return md5str;     
}
开发者ID:Wenchy,项目名称:tinyFTP,代码行数:20,代码来源:common.cpp


示例14: get_signature

// computes an RSA-MD5 signature over 'buf' using 'priv_key'
// signature data is returned is 'sig_buf' which should be at least
// SIGNATURE_LEN bytes in size.  
// Method returns 0 on success.   
int get_signature(char *buf, unsigned int buf_size, RSA *priv_key,
                   unsigned char *sig_buf, unsigned int *sig_len) {

  unsigned char digest[16];
  unsigned int digest_len = 16;
  MD5_CTX md5;
  MD5_Init(&md5);
  MD5_Update(&md5, (unsigned char*)buf, buf_size);
  MD5_Final(digest, &md5);

  int ret_val = RSA_sign(NID_md5, digest, digest_len, 
			sig_buf, sig_len, priv_key);
  if(!ret_val) {
      unsigned long e = ERR_get_error();
      DPRINTF(DEBUG_ERROR,"RSA_sign error: %s", ERR_error_string(e, buf));
      return 1;
  }
 
  return 0;
}
开发者ID:katmagic,项目名称:perspectives-notary-server,代码行数:24,代码来源:notary_crypto.c


示例15: main

int main( int argc, char **argv )
{
    MD5_CTX ctx;
    unsigned char *data="123";
    unsigned char md[16];
    char buf[33]={'\0'};
    char tmp[3]={'\0'};
    int i;

    MD5_Init(&ctx);
    MD5_Update(&ctx,data,strlen(data));
    MD5_Final(md,&ctx);

    for( i=0; i<16; i++ ){
        sprintf(tmp,"%02X",md[i]);
        strcat(buf,tmp);
    }
    printf("%s\n",buf);
    return 0;
}
开发者ID:spitbreak,项目名称:Algorithm,代码行数:20,代码来源:md5.c


示例16: generate_md5_hashes

void generate_md5_hashes(char* input_data, int count, unsigned char* result)
{
    MD5_CTX md5;
    
    unsigned char md5_result[16] = {0};

    int i;
    for(i = 0; i < count; i++)
    {
	MD5_Init(&md5);
	
	MD5_Update(&md5, input_data, strlen(input_data));
	input_data += INPUT_MAX_LENGTH;
	
	MD5_Final(md5_result, &md5);

	memcpy(result, md5_result, 16);
	result += 16;
    }
}
开发者ID:Jassob,项目名称:advent_of_code_2016,代码行数:20,代码来源:day05.c


示例17: ntlm_generate_signing_key

int ntlm_generate_signing_key(BYTE* exported_session_key, PSecBuffer sign_magic, BYTE* signing_key)
{
	int length;
	BYTE* value;
	MD5_CTX md5;
	length = 16 + sign_magic->cbBuffer;
	value = (BYTE*) malloc(length);

	if (!value)
		return -1;

	/* Concatenate ExportedSessionKey with sign magic */
	CopyMemory(value, exported_session_key, 16);
	CopyMemory(&value[16], sign_magic->pvBuffer, sign_magic->cbBuffer);
	MD5_Init(&md5);
	MD5_Update(&md5, value, length);
	MD5_Final(signing_key, &md5);
	free(value);
	return 1;
}
开发者ID:AMV007,项目名称:FreeRDP,代码行数:20,代码来源:ntlm_compute.c


示例18: sizeof

ClientWardenModule* WardenWin::GetModuleForClient(WorldSession* /*session*/)
{
    ClientWardenModule* mod = new ClientWardenModule;

    uint32 len = sizeof(Module_79C0768D657977D697E10BAD956CCED1_Data);

    // data assign
    mod->CompressedSize = len;
    mod->CompressedData = new uint8[len];
    memcpy(mod->CompressedData, Module_79C0768D657977D697E10BAD956CCED1_Data, len);
    memcpy(mod->Key, Module_79C0768D657977D697E10BAD956CCED1_Key, 16);

    // md5 hash
    MD5_CTX ctx;
    MD5_Init(&ctx);
    MD5_Update(&ctx, mod->CompressedData, len);
    MD5_Final((uint8*)&mod->ID, &ctx);

    return mod;
}
开发者ID:Phentora,项目名称:OregonCore,代码行数:20,代码来源:WardenWin.cpp


示例19: sizeof

ClientWardenModule* WardenWin::GetModuleForClient()
{
    ClientWardenModule *mod = new ClientWardenModule;

    uint32 length = sizeof(Module.Module);

    // data assign
    mod->CompressedSize = length;
    mod->CompressedData = new uint8[length];
    memcpy(mod->CompressedData, Module.Module, length);
    memcpy(mod->Key, Module.ModuleKey, 16);

    // md5 hash
    MD5_CTX ctx;
    MD5_Init(&ctx);
    MD5_Update(&ctx, mod->CompressedData, length);
    MD5_Final((uint8*)&mod->Id, &ctx);

    return mod;
}
开发者ID:Tithand,项目名称:TER-Server,代码行数:20,代码来源:WardenWin.cpp


示例20: cipher_set_key_string

/*
 * Selects the cipher, and keys if by computing the MD5 checksum of the
 * passphrase and using the resulting 16 bytes as the key.
 */
int
cipher_set_key_string(struct sshcipher_ctx *cc, struct sshcipher *cipher,
    const char *pphrase, int do_encrypt)
{
	MD5_CTX md;
	u_char digest[16];
	int ret = SSH_ERR_LIBCRYPTO_ERROR;

	if (MD5_Init(&md) != 1 ||
	    MD5_Update(&md, (const u_char *)pphrase, strlen(pphrase)) != 1 ||
	    MD5_Final(digest, &md) != 1)
		goto out;

	ret = cipher_init(cc, cipher, digest, 16, NULL, 0, do_encrypt);

 out:
	memset(digest, 0, sizeof(digest));
	memset(&md, 0, sizeof(md));
	return ret;
}
开发者ID:mpitzl,项目名称:libopenssh,代码行数:24,代码来源:cipher.c



注:本文中的MD5_Init函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ MD5_Update函数代码示例发布时间:2022-05-30
下一篇:
C++ MD5_Final函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap