Install openssl&& compile run test code under Ubuntu

Source: Internet
Author: User
Tags hmac install openssl openssl

Check if OpenSSL is installed:

sudo apt-get install OpenSSL

If you have installed, do the following:
sudo apt-get install Libssl-dev
sudo apt-get install libssl0.9.8

Install GTK + Development Library under Ubuntu
sudo apt-get install Libgtk2.0-dev

Code:

 #include <stdio.h> #include <string.h> #include <openssl/hmac.h > int main () {//The secret key for hashing char key[] = "f5f48fc13505425891fb429f99d66171"; char user[] = "Fazio    "; Char api_key[] = "4894A1A7B78E44B6A449C5299B1AFC24"; char nonce[] = "000000"; char *data = malloc (strlen (user) +strlen (API       _key) +strlen (nonce) +1); strcpy (Data,user); strcat (Data,api_key) strcat (data,nonce);p rintf ("%s \ n", data);    unsigned char* result;     unsigned int len = 65;     result = (unsigned char*) malloc (sizeof (char) * len);    Hmac_ctx CTX;     Hmac_ctx_init (&CTX);    HMAC_INIT_EX (&ctx, Key, strlen (key), evp_sha256 (), NULL);    Hmac_update (&ctx, (unsigned char*) data, strlen (data));    Hmac_final (&ctx, result, &len);     Hmac_ctx_cleanup (&CTX);     printf ("HMAC Digest:"); int i;     for (i = 0; I! = len; i++) printf ("%02x", (unsigned int) result[i]);     printf ("\ n");     Free (result); return 0;} 

Compilation: Gcc-o test Test.c-lssl-lcrypto

Operation Result:

fazio4894a1a7b78e44b6a449c5299b1afc24000000
HMAC DIGEST:6764F0C105DCFA9FC143AEA534232C297AB2BA4E362FD87AF5EB0A26B270E0EB

Install openssl&& compile run test code under Ubuntu

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.