openssl-EVP_md5()
作者:互联网
#include <stdio.h> #include <stdint.h> #include <strings.h> #include <openssl/dh.h> #include <openssl/evp.h> static void hex_print(const char *name, const unsigned char *buf, size_t len){ printf("%s: ", name); for (size_t i = 0; i < len; i++){ printf("%02X", buf[i]); } printf("\n"); } int main(){ char *information = "hello"; EVP_MD_CTX ctx; EVP_MD_CTX_init(&ctx); #ifdef EVP_MD_CTX_FLAG_NON_FIPS_ALLOW if (FIPS_mode()) { EVP_MD_CTX_set_flags(&ctx,EVP_MD_CTX_FLAG_NON_FIPS_ALLOW); } #endif EVP_DigestInit_ex(&ctx,EVP_md5(), NULL); EVP_DigestUpdate(&ctx,information,sizeof(information)); uint8_t digest[1024] = {0}; bzero(digest,sizeof(digest)); uint digestlength = 0; EVP_DigestFinal(&ctx, digest, &digestlength); EVP_MD_CTX_cleanup(&ctx); hex_print("EVP_md5()",digest,digestlength); return 0; }
编译:gcc demo.c -lcrypto
输出:
标签:MD,ctx,CTX,openssl,EVP,include,digest,md5 来源: https://www.cnblogs.com/iuyy/p/13489634.html