当前位置: 首页>>代码示例>>C++>>正文


C++ MD5_Update函数代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: 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

示例6: 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:Myst,项目名称:ElunaTrinityCata,代码行数:20,代码来源:WardenWin.cpp

示例7: sizeof

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

    uint32 len = sizeof(Module_0DBBF209A27B1E279A9FEC5C168A15F7_Data);

    // data assign
    mod->CompressedSize = len;
    mod->CompressedData = new uint8[len];
    memcpy(mod->CompressedData, Module_0DBBF209A27B1E279A9FEC5C168A15F7_Data, len);
    memcpy(mod->Key, Module_0DBBF209A27B1E279A9FEC5C168A15F7_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:Anonymus123,项目名称:AtomicCore-2.4.3,代码行数:20,代码来源:WardenMac.cpp

示例8: 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

示例9: MD5_File

/*
 * Compute the MD5 checksum of a file.  The md parameter must
 * point to a buffer containing at least MD5_DIGEST_SIZE bytes.
 *
 * Do not confuse OpenSSL's MD5_DIGEST_LENGTH with our own
 * MD5_DIGEST_SIZE macro.
 */
int
MD5_File(char *path, char *md)
{
	char buf[1024];
	MD5_CTX ctx;
	ssize_t n;
	int fd;

	fd = open(path, O_RDONLY);
	if (fd == -1)
		return (-1);
	MD5_Init(&ctx);
	while ((n = read(fd, buf, sizeof(buf))) > 0)
		MD5_Update(&ctx, buf, n);
	close(fd);
	if (n == -1)
		return (-1);
	MD5_End(md, &ctx);
	return (0);
}
开发者ID:JabirTech,项目名称:Source,代码行数:27,代码来源:misc.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: sizeof

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

    uint32 length = sizeof(Module_79C0768D657977D697E10BAD956CCED1_Data);

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

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

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

示例12: 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

示例13: 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

示例14: md5

//Return value is on the heap.
char* md5(const char *filename) {

	//Open the input file.
	FILE *in_file = fopen(filename, "rb");

	if (!in_file) {
		printf ("%s can't be opened.\n", filename);
		return NULL;
	}

	//Initialise the md5 function.
	MD5_CTX md_context;
	MD5_Init (&md_context);
	
	//Read in the data from the file and feed it to the md5 function.
	int bytes;
	unsigned char data[1024];

	while ((bytes = fread(data, 1, 1024, in_file)) != 0) {
		MD5_Update(&md_context, data, bytes);
	}

	//Recieve the final md5 value inside c.
	unsigned char c[MD5_DIGEST_LENGTH];
	MD5_Final(c,&md_context);

	//Allocate memory for the return value.
	char tmp[2];
	char *hash = malloc((MD5_DIGEST_LENGTH * 2) + 1);

	//Format the md5 digits as chars.
	for (int i = 0; i < MD5_DIGEST_LENGTH; i++) {
		sprintf(tmp, "%02x", c[i]);
		memcpy(hash+(i*2), tmp, 2);
	}

	hash[MD5_DIGEST_LENGTH*2] = '\0';
	fclose (in_file);

	return hash;
}
开发者ID:klampworks,项目名称:md5me,代码行数:42,代码来源:main.c

示例15: safe_open_wrapper_follow

bool Condor_MD_MAC::addMDFile(const char * filePathName)
{
#ifdef HAVE_EXT_OPENSSL
	int fd;

    fd = safe_open_wrapper_follow(filePathName, O_RDONLY | O_LARGEFILE, 0);
    if (fd < 0) {
        dprintf(D_ALWAYS,
                "addMDFile: can't open %s: %s\n",
                filePathName,
                strerror(errno));
        return false;
    }

	unsigned char *buffer;	

	buffer = (unsigned char *)calloc(1024*1024, 1);
	ASSERT(buffer != NULL);

	bool ok = true;
	ssize_t count = read(fd, buffer, 1024*1024); 
	while( count > 0) {
		MD5_Update(&(context_->md5_), buffer, count); 
		memset(buffer, 0, 1024*1024);
		count = read(fd, buffer, 1024*1024); 
	}
	if (count == -1) {
		dprintf(D_ALWAYS,
		        "addMDFile: error reading from %s: %s\n",
		        filePathName,
		        strerror(errno));
		ok = false;
	}

	close(fd);
	free(buffer);
	return ok;
#else
	return false;
#endif
}
开发者ID:AlanDeSmet,项目名称:htcondor,代码行数:41,代码来源:condor_md.cpp


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