gpt4 book ai didi

将 BIGNUM 转换为原始二进制文件

转载 作者:太空宇宙 更新时间:2023-11-03 14:22:30 27 4
gpt4 key购买 nike

我想使用 BIGNUM 的 BN_bn2bin 函数将这个十六进制字符串转换成原始二进制文件

    BN_hex2bn(&asn1hash, "3031300D060960864801650304020105000420BC5F9353CBB9DCAE86B9F8F68C1C95856DB836ACA2E00C9319716CDF4DD0F5BA");

char *buf = (unsigned char *)malloc(BN_num_bytes(asn1hash));

BN_bn2bin(asn1hash, buf);
FILE *fp;
fp = fopen("ASn1Hash","wb+");

fputs(buf, fp);
fclose(fp);

但为什么只有“30 31 30 0D 06 09 60 86 48 01 65 03 04 02 01 05”输出到文件中?

最佳答案

感谢修改代码

BN_hex2bn(&asn1hash, "3031300D060960864801650304020105000420BC5F9353CBB9DCAE86B9F8F68C1C95856DB836ACA2E00C9319716CDF4DD0F5BA");

int num_bytes = BN_num_bytes(asn1hash);
char *buf = (unsigned char *)malloc(num_bytes);

BN_bn2bin(asn1hash, buf);
FILE *fp;
fp = fopen("ASn1Hash","wb+");

fwrite(buf, 1, num_bytes, fp);
fclose(fp);

关于将 BIGNUM 转换为原始二进制文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59449087/

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