MD5 和 SHA1 C++ 散列库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4678447/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
MD5 and SHA1 C++ hashing library
提问by 0x77D
I'm trying to find a good (and well documented) hashing library to use with my C++ program, I only need to generate two hashes from a string.
我正在尝试找到一个好的(并且有据可查的)散列库来与我的 C++ 程序一起使用,我只需要从一个字符串生成两个散列。
I've tried with crypto++
and mhash
and I didn't manage to make them work, also with http://www.zedwood.com/article/121/cpp-md5-function
我试着crypto++
和mhash
我没有设法让他们的工作,也与http://www.zedwood.com/article/121/cpp-md5-function
I would be glad if this library is cross-platform.
如果这个库是跨平台的,我会很高兴。
采纳答案by programmer
Try this open source library http://hashlib2plus.sourceforge.net/
回答by peenut
Search before ask, there is already question: What is the best encryption library in C/C++?
在问之前搜索,已经有问题了: C/C++ 中最好的加密库是什么?
Solutions like OpenSSL and Crypto++ are cross-platform, if you "didn't manage to make them work", you should have been more specific like: I use OS xyz version xyz, compiler xyz version xyz, IDE xyz version xyz, trying to get work library xyz version xyz from http://xyz, and it does not work, because xyz errors.
像 OpenSSL 和 Crypto++ 这样的解决方案是跨平台的,如果你“没有设法让它们工作”,你应该更具体:我使用 OS xyz 版本 xyz,编译器 xyz 版本 xyz,IDE xyz 版本 xyz,试图从http://xyz获取工作库 xyz 版本 xyz ,但它不起作用,因为 xyz 错误。
回答by davka
see my answer here. The original sample is taken from here, and operates on std::string
rather than on std::istream
. There are many good samples on cryptopp wiki, I'll try to look for some I used.
在这里看到我的答案。原始样本取自此处,并在 上std::string
而不是上进行操作std::istream
。cryptopp wiki 上有很多很好的示例,我会尝试寻找一些我使用过的示例。
here's a sample from my code:
这是我的代码中的一个示例:
#include <cryptopp/md5.h>
byte digest[AES::BLOCKSIZE];
MD5().CalculateDigest(digest, (byte*)input.data(), input.size());
Here's the list of cryptopp sampleson their wiki. Look at HashFunctions and HashFilter.
这是他们 wiki 上的cryptopp 示例列表。查看 HashFunctions 和 HashFilter。