gpt4 book ai didi

hash - 获取所有支持的摘要算法的列表

转载 作者:行者123 更新时间:2023-12-02 06:07:39 30 4
gpt4 key购买 nike

我想知道如何动态获取所有支持的摘要算法的 EVP_MD* 列表。目前我正在使用静态数组

const EVP_MD* aHashAlgos[] = { EVP_sha512(), EVP_sha384(), EVP_sha256() ... }

谢谢!

最佳答案

下面将列出所有已注册的摘要方法。

#include <openssl/evp.h>
#include <openssl/objects.h>
#include <stdio.h>

void my_callback(const OBJ_NAME *obj, void *arg)
{
printf("Digest: %s\n", obj->name);
}

int main(int argc, char *argv)
{
void *my_arg;
OpenSSL_add_all_digests(); //make sure they're loaded

my_arg = NULL;
OBJ_NAME_do_all(OBJ_NAME_TYPE_MD_METH, my_callback, my_arg);
}

回调接收OBJ_NAME类型的对象:

typedef struct obj_name_st {
int type;
int alias;
const char *name;
const char *data;
} OBJ_NAME;

您可以通过EVP_get_digestbyname()查找关联的EVP_MD*。此方法会找到很多东西,其中许多可能是您不想要的:

$ ./a.out
Digest: ripemd160WithRSA
Digest: ssl2-md5
Digest: sha384
Digest: sha224
Digest: SHA224
Digest: md4
Digest: sha512
Digest: RSA-SHA256
Digest: DSA-SHA
Digest: sha1WithRSAEncryption
Digest: MD5
Digest: MD4
Digest: ssl3-sha1
Digest: ripemd160
Digest: sha
Digest: SHA384
Digest: SHA1
Digest: ssl3-md5
Digest: sha256
Digest: sha384WithRSAEncryption
Digest: SHA512
Digest: DSA-SHA1-old
Digest: dsaWithSHA1
Digest: ecdsa-with-SHA1
Digest: whirlpool
Digest: RSA-RIPEMD160
Digest: rmd160
Digest: RIPEMD160
Digest: RSA-SHA1-2
Digest: RSA-SHA1
Digest: dsaWithSHA
Digest: md5WithRSAEncryption
Digest: DSS1
Digest: RSA-MD5
Digest: dsaEncryption
Digest: ripemd
Digest: md4WithRSAEncryption
Digest: DSA
Digest: sha512WithRSAEncryption
Digest: SHA
Digest: dss1
Digest: RSA-SHA224
Digest: RSA-SHA512
Digest: SHA256
Digest: md5
Digest: RSA-SHA384
Digest: sha1
Digest: sha224WithRSAEncryption
Digest: RSA-SHA
Digest: shaWithRSAEncryption
Digest: sha256WithRSAEncryption
Digest: DSA-SHA1
Digest: RSA-MD4

关于hash - 获取所有支持的摘要算法的列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47476427/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com