Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to calculate a SHA-512 hash in C++ on Linux?

Is there a standard library or commonly used library that can be used for calculating SHA-512 hashes on Linux?

I'm looking for a C or C++ library.

like image 928
Nathan Osman Avatar asked Feb 26 '11 04:02

Nathan Osman


People also ask

How do I calculate the SHA-512 hash of a file?

Here is how to do it. Suppose you have a file called “x-410.pdf” on your hard drive and it is in your folder called “C: emp”. Suppose you wish to calculate the SHA-512 hash of this file (what the USPTO calls its “message digest”). You can open a command line window and navigate to that folder.

How does print work with SHA512?

Prints checksum in binary, no file name. Reads a file containing hashes that were produced by a previous run of sha512 and checks them. The file containing the hashes should be the output of a former run of sha512. That is, each line must contain the name of the file and the check-sum in hexadecimal. For example:

How to crypt to use SHA-512 in Python?

In these examples the password is the string "password" and the salt is "saltsalt". Both examples are using $6$ which denotes that you want crypt to use SHA-512. For the python one-liner, you can use crypt.mksalt (crypt.METHOD_SHA512) to generate the salt instead of using a fixed one.

Why am I getting an error message from SHA512?

Error messages are sent to standard error (stderr). ICSF (at least FMID HCR77A0) must be installed and running because sha512 uses the ICSF One-Way Hash Generate callable service. If resource CSFOWH has been defined, the user running the command must have READ access to the CSFOWH profile in the RACF CSFSERV general resource class.


1 Answers

Have you checked OpenSSL. I myself have not used it but documentation says it supports it.

Here is list of few more implementations.

Example code

 md = EVP_get_digestbyname("sha512");
 EVP_MD_CTX_init(&mdctx);
 EVP_DigestInit_ex(&mdctx, md, NULL);
 EVP_DigestUpdate(&mdctx, mess1, strlen(mess1));
 EVP_DigestUpdate(&mdctx, mess2, strlen(mess2));
 EVP_DigestFinal_ex(&mdctx, md_value, &md_len);
 EVP_MD_CTX_cleanup(&mdctx);
like image 134
Zimbabao Avatar answered Oct 14 '22 00:10

Zimbabao