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

输出:

openssl-EVP_md5()

 

上一篇:Amazon Linux下解决*服务端EVP_CIPHER_CTX_cleanup() 函数报错


下一篇:银联支付接口调试