How can I use openssl/md5 in C++ to crypt a string?

和自甴很熟 提交于 2019-12-01 09:27:23
Morten Kristensen

You should take a look at the documentation. An option is to use this function:

#include <openssl/md5.h>
unsigned char *MD5(const unsigned char *d, 
                   unsigned long n,
                   unsigned char *md);

To which they state:

MD2(), MD4(), and MD5() compute the MD2, MD4, and MD5 message digest of the n bytes at d and place it in md (which must have space for MD2_DIGEST_LENGTH == MD4_DIGEST_LENGTH == MD5_DIGEST_LENGTH == 16 bytes of output). If md is NULL, the digest is placed in a static array.

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

#define AES_BLOCK_SIZE 16

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.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!