如何在Linux上计算c++中的SHA-512哈希?

时间:2021-02-20 18:24:36

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

是否有一个标准库或常用库可以用于计算Linux上的SHA-512哈希?

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

我在找一个C或c++库。

4 个解决方案

#1


11  

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

你检查OpenSSL。我自己没有使用过它,但是文档说它支持它。

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);

#2


5  

I'm using Botan for various cryptographic purposes. It has many kinds of SHA(-512) algorithms.

为了各种加密目的,我正在使用Botan。它有许多种SHA(-512)算法。

When I was looking at C++ crypto libraries I also found Crypto++. The style of the Botan API was more straightforward for me, but both of these libraries are solid and mature.

当我在查看c++密码库时,我还发现了密码+。Botan API的风格对我来说更简单,但是这两个库都是可靠和成熟的。

#3


4  

Check this code. It is fully portable and does not need any additional configurations. Only STL would suffice. You'll just need to declare

检查该代码。它是完全可移植的,不需要任何额外的配置。只有STL就足够了。你只需要申报

#include "sha512.hh"

and then use the functions

然后用函数

sw::sha512::calculate("SHA512 of std::string") // hash of a string, or
sw::sha512::file(path) // hash of a file specified by its path, or
sw::sha512::calculate(&data, sizeof(data)) // hash of any block of data

whenever you need them. Their return value is std::string

无论何时你需要他们。它们的返回值是std::string

#4


0  

I have had great success with this:

我在这方面取得了巨大的成功:

Secure Hash Algorithm (SHA)

安全散列算法(SHA)

BSD license. It covers SHA-1, SHA-224, SHA-256, SHA-384, and SHA-512. It has neat helper functions reduce steps for simple cases:

BSD许可。它包括SHA-1、SHA-224、SHA-256、SHA-384和SHA-512。它有整洁的助手功能,减少了简单情况下的步骤:

SHA256_Data(const sha2_byte* data, size_t len, char digest[SHA256_DIGEST_STRING_LENGTH])

It also has a lot of performance tuning options.

它还有很多性能调优选项。

#1


11  

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

你检查OpenSSL。我自己没有使用过它,但是文档说它支持它。

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);

#2


5  

I'm using Botan for various cryptographic purposes. It has many kinds of SHA(-512) algorithms.

为了各种加密目的,我正在使用Botan。它有许多种SHA(-512)算法。

When I was looking at C++ crypto libraries I also found Crypto++. The style of the Botan API was more straightforward for me, but both of these libraries are solid and mature.

当我在查看c++密码库时,我还发现了密码+。Botan API的风格对我来说更简单,但是这两个库都是可靠和成熟的。

#3


4  

Check this code. It is fully portable and does not need any additional configurations. Only STL would suffice. You'll just need to declare

检查该代码。它是完全可移植的,不需要任何额外的配置。只有STL就足够了。你只需要申报

#include "sha512.hh"

and then use the functions

然后用函数

sw::sha512::calculate("SHA512 of std::string") // hash of a string, or
sw::sha512::file(path) // hash of a file specified by its path, or
sw::sha512::calculate(&data, sizeof(data)) // hash of any block of data

whenever you need them. Their return value is std::string

无论何时你需要他们。它们的返回值是std::string

#4


0  

I have had great success with this:

我在这方面取得了巨大的成功:

Secure Hash Algorithm (SHA)

安全散列算法(SHA)

BSD license. It covers SHA-1, SHA-224, SHA-256, SHA-384, and SHA-512. It has neat helper functions reduce steps for simple cases:

BSD许可。它包括SHA-1、SHA-224、SHA-256、SHA-384和SHA-512。它有整洁的助手功能,减少了简单情况下的步骤:

SHA256_Data(const sha2_byte* data, size_t len, char digest[SHA256_DIGEST_STRING_LENGTH])

It also has a lot of performance tuning options.

它还有很多性能调优选项。