Advertisement
Guest User

HMAC-SHA256

a guest
Jun 8th, 2014
370
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.61 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <openssl/evp.h>
  5. #include <openssl/hmac.h>
  6.  
  7. int main()
  8. {
  9.     char msg[] = "A simple string";
  10.     char key[] = "key";
  11.    
  12.     HMAC_CTX hmac;
  13.     HMAC_Init_ex(&hmac, key, strlen(key), EVP_sha256(), NULL);
  14.     HMAC_Update(&hmac, (const unsigned char*)msg, strlen(msg));
  15.    
  16.     unsigned int md_len = HMAC_size(&hmac);
  17.     unsigned char md[md_len];
  18.     HMAC_Final(&hmac, md, &md_len);
  19.    
  20.     // dump resulting digest
  21.     for (size_t i=0; i<md_len; ++i)
  22.         printf("%02X", md[i]);
  23.     printf("\n");
  24.    
  25.     return 0;
  26.    
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement