Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <openssl/sha.h>
  4.  
  5. int main()
  6. {
  7. unsigned char digest[SHA512_DIGEST_LENGTH];
  8. char string[] = "hello world";
  9.  
  10. SHA512((unsigned char*)&string, strlen(string), (unsigned char*)&digest);
  11.  
  12. char mdString[SHA512_DIGEST_LENGTH*2+1];
  13.  
  14. for(int i = 0; i < SHA512_DIGEST_LENGTH; i++)
  15. sprintf(&mdString[i*2], "%02x", (unsigned int)digest[i]);
  16.  
  17. printf("SHA512 digest: %sn", mdString);
  18.  
  19. return 0;
  20. }
  21.  
  22. gcc sha512_sample1.cpp -o sample1 -lcrypto
  23.  
  24. ~$ ./sample1
  25. SHA512 digest: 309ecc489c12d6eb4cc40f50c902f2b4d0ed77ee511a7c7a9bcd3ca86d4cd86f989dd35bc5ff499670da34255b45b0cfd830e81f605dcf7dc5542e93ae9cd76f
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement