Tag: md5

在C中返回错误的MD5哈希

我正在尝试使用原始/未触摸的md5.h和来自http://www.arp.harvard.edu的 md5c.c为字符串“Hello World”生成MD5哈希。 但我的结果与我测试的所有md5在线工具不同。 这个代码怎么了? 谢谢。 #include #include #include #include “md5.h” void MD5hash(unsigned char *data, unsigned int dataLen, unsigned char *digest) { MD5_CTX c; MD5Init(&c); MD5Update(&c, data, dataLen); MD5Final(digest, &c); } int main(int argc, const char * argv[]) { unsigned char digest[16]; const char *s = “Hello World”; unsigned int l = (unsigned int)strlen(s); MD5hash((unsigned […]

MD5加密API为某些明文返回错误的哈希值

我正在尝试使用Microsoft加密API来计算MD5哈希值,但是我得到的哈希值不正确: #include #include #include char* HashMD5(char* data, DWORD *result) { DWORD dwStatus = 0; DWORD cbHash = 16; int i = 0; HCRYPTPROV cryptProv; HCRYPTHASH cryptHash; BYTE hash[16]; char *hex = “01234567879abcdef”; char *strHash = “00000000000000000000000000000000”; if(!CryptAcquireContext(&cryptProv, NULL, MS_DEF_PROV, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) { dwStatus = GetLastError(); printf(“CryptAcquireContext failed: %d\n”, dwStatus); *result = dwStatus; return NULL; } […]

将MD5结果转换为C中的整数

我的目标是使用MD5结果的结果来索引哈希表。 我想对它执行Modulo操作以在表中找到适当的插槽。 我已经尝试将它作为无符号长长型投射。 当我打印结果时,我每次都得到一个不同的数字用于相同的MD5哈希。 MD5哈希最初是unsigned char *。 有人能告诉我我做错了什么吗? 这是我的function: int get_fp_slot(unsigned char * fingerprint, int size) { return (unsigned long long)fingerprint % size; }

使用零流优化更新MD5 / SHA1

是否可以优化function: MD5_Update(&ctx_d, buf, num); 如果你知道buf只包含零? 或者这在数学上是不可能的? 同样适用于SHA1。

md5参考错误

我在我的mac上编译了一个正确工作的md5程序但是当我尝试在我的ubuntu发行版上编译它时出错了: /tmp/ccKBJiV3.o: In function `str2md5′: md5.c:(.text+0x33): undefined reference to `MD5_Init’ md5.c:(.text+0x5b): undefined reference to `MD5_Update’ md5.c:(.text+0x79): undefined reference to `MD5_Update’ md5.c:(.text+0xa2): undefined reference to `MD5_Final’ collect2: ld returned 1 exit status 以下是我的主要代码: #include #include #include #include “md5.h” #include #include int main(int argc, char *argv[]) { char *output = str2md5(argv[1], strlen(argv[1])); printf(“%s\n”, output); free(output); return 0; […]

是否有一个MD5库不同时需要整个输入?

我正在研究Objective C Cocoa应用程序。 我在CommonCrypto中测试了CC_MD5 ,它运行得很好; 然而,当我给它5个gygabyte文件时,我的整个计算机冻结并崩溃。 MD5算法将输入处理为512字节的块,并不一次真正需要所有输入。 在Objective C或C中是否有一个库要求下一个512字节的块而不是一次性获取所有输入?

MD5 HMAC与OpenSSL

我试图用OpenSSL生成MD5 HMAC并且大部分代码都是借用的。 生成的hmac不正确: #include #include #include #include #include #include #include #include #include #include int main() { unsigned char* key = (unsigned char*) “2012121220121212201212122012121220121212201212122012121220121212”; unsigned char* data = (unsigned char*) “johndoejohndoejohndoejohndoejohndoejohndoejohndoejohndoejohndoejohndoejohndoejohndoe”; unsigned char* expected = (unsigned char*) “abcd1d87dca34f334786307d0da4fcbd”; unsigned char* result; // unsigned int result_len = 16; unsigned int result_len = 16; int i; static char […]

如何在C ++中使用openssl / md5来加密字符串?

我需要在我的程序中将md5中的字符串加密。 有一个lib openssl,但我是一个新手。 如何使用它来加密一个字符串,哪里可以找到一个好的doc,教我如何使用这个lib,还有其他函数如aes? 我试过这段代码: int main() { unsigned char result[MD5_DIGEST_LENGTH]; const unsigned char* str; str = (unsigned char*)”hello”; unsigned int long_size = 100; MD5(str,long_size,result); } 但是编译器告诉我:未定义的MD5引用。 为什么MD5有未定义的引用?

如何计算C中大文件的MD5哈希值?

我使用OpenSSL库在C语言编写。 如何使用md5计算大文件的哈希值? 据我所知,我需要将整个文件作为char数组加载到RAM中,然后调用哈希函数。 但是如果文件大约是4Gb呢? 听起来不错。 解决 :感谢askovpen ,我发现了我的错误。 我用过 while ((bytes = fread (data, 1, 1024, inFile)) != 0) MD5_Update (&mdContext, data, 1024); 不 while ((bytes = fread (data, 1, 1024, inFile)) != 0) MD5_Update (&mdContext, data, bytes);

可以将md5分解为跨多个核心/线程运行吗?

在计算大文件的md5总和时,我看到单个cpu核心跳转到100%,无论多长时间,让所有其他核心空闲。 我对md5的基本理解是整个过程是完全线性的,其中值依赖于所有先前读取的值,并且我们无法做任何事情来使其成为multithreading的。 这是真的? 或者有没有办法将文件分成几个部分,使用多核计算多个部分的 ,然后将这些值组合到最终的md5中? 我们用来计算md5sum的库是http://libmd5-rfc.sourceforge.net/但如果有可能在多个内核中打破md5sum以便更快完成,我会切换到另一个库。 (注意:改为md5以外的东西不是问题,也不能这样做,因为它接口的其他封闭系统。也不是关于使用md5的安全性的问题。)