如何在 C++ 中使用 openssl/md5哈希字符串?
我需要在程序中使用 md5 算法对字符串进行哈希处理。 有 lib openssl 但我是它的新手。 如何使用它对字符串进行哈希处理?我在哪里可以找到一个好的文档来教我如何使用这个库,以及 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
的未定义引用?
I need to hash with md5 algorithm a string in my program.
There is the lib openssl but I'm a newbie about it.
How is possible hash a string using that and where I can find a good doc that teach me how to use this lib, also with other function like aes?
I've tried this code:
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);
}
But the compiler told me:
undefined reference to MD5
.
Why is there and undefined reference to MD5
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该查看文档。一种选择是使用此功能:
他们对此表示:
至于 AES,如果您还想使用 OpenSSL,请查看 EVP 文档和此示例说明如何使用它。但请注意,您必须
在文件顶部添加 In 才能使其正常工作。
顺便提一句。我真的可以推荐 Crypto++ 库,因为它很棒并且具有各种加密原语; AES、椭圆曲线、MAC、公钥加密等。
You should take a look at the documentation. An option is to use this function:
To which they state:
As for AES, if you also want to use OpenSSL, then take a look at EVP doc and this example of how to use it. Just note that you have to add
In the top of the file for it to work, though.
Btw. I can really recommend the Crypto++ library since it's great and has all kinds of cryptographic primitives; AES, Elliptic Curves, MAC, public-key crypto and so on.
MD5 函数现已弃用,因此,如果您想避免代码中出现所有这些讨厌的警告...
以下是如何在 OpenSSL 3.0 及更高版本中使用 C++ 使用 md5 的简单示例:
根据: https://www.openssl.org/docs/man3.0/man3/EVP_DigestInit_ex.html
The MD5 function is now deprecated, so if you want to avoid all those nasty warnings in your code...
Here's a simple example of how to use md5 with OpenSSL 3.0 and above with C++:
According to: https://www.openssl.org/docs/man3.0/man3/EVP_DigestInit_ex.html