使用OpenSSL库在C ++中生成SHA-3哈希 [英] Generate SHA-3 hash in C++ using OpenSSL library
问题描述
我已经广泛搜索了一个代码示例,该示例使用OpenSSL最近实现的SHA-3算法进行哈希处理,但找不到任何示例.在SHA-1和SHA-3上有代码示例,但是在库文件夹中快速搜索显示OpenSSL v1.1.1中甚至没有SHA3函数名称?
I've searched extensively for a code example that uses OpenSSL's recently implemented SHA-3 algorithm for hashing but couldn't find any. There are code examples on SHA-1 and SHA-3 but a quick search in the library folders reveal that there isn't even a SHA3 function name in OpenSSL v1.1.1?
我到处搜索过,但这是相对较新的内容,因此我无法找到有关新算法的任何特定信息.
I've searched everywhere but this is relatively new and I have not been able to track down any information specifically regarding the new algorithm.
我发现此线程使用OpenSSL库在C ++中生成SHA哈希涵盖了SHA-1和SHA-2,但是库中实际上没有SHA3函数-Keccak1600看起来像SHA-3的名字吗?
I found this thread that Generate SHA hash in C++ using OpenSSL library covers SHA-1 and SHA-2 but there isn't actually a SHA3 function in the library - Keccak1600 seems like name for SHA-3?
推荐答案
此页面上有一些用于生成哈希的通用示例代码:
There is some generic sample code for generating a hash on this page:
https://wiki.openssl.org/index.php/EVP_Message_Digests
该特定代码生成SHA256哈希.要将其转换为使用SHA3,请将EVP_sha256()
的两个实例替换为EVP_sha3_224()
,EVP_sha3_256()
,EVP_sha3_384()
或EVP_sha3_512()
之一.
That particular code generates a SHA256 hash. To convert it to use SHA3 instead, replace the two instances of EVP_sha256()
with one of EVP_sha3_224()
, EVP_sha3_256()
, EVP_sha3_384()
or EVP_sha3_512()
as appropriate.
这篇关于使用OpenSSL库在C ++中生成SHA-3哈希的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!