gpt4 book ai didi

c - 带有 libssl 的 EMSA_PSS_ENCODE

转载 作者:太空宇宙 更新时间:2023-11-04 04:58:11 24 4
gpt4 key购买 nike

您好,我正在尝试使用 libssl 通过 libssl 中的 RSA_padding_add_PKCS1_type1 函数获取一些 EMSA_PSS_ENCODING,但我找不到文档或解决方案,所以这是我编写的示例代码:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <openssl/rsa.h>
#include <openssl/err.h>

FILE *error_file;

int main()
{
int lSize;
const unsigned char *string1= (unsigned char *)"The pen is on the table";
unsigned char *stringa=NULL;
int num = 64;
if ((stringa = (unsigned char *)OPENSSL_malloc(num)) == NULL)
fprintf(stderr,"OPENSSL_malloc error\n");
lSize = strlen((char *)string1);

fprintf(stdout,"string1 len is %u\n",lSize);
if(RSA_padding_add_PKCS1_type_1(stringa,num,string1,lSize) != 1)
fprintf(stderr,"Error: RSA_PADDING error\n");

error_file = fopen("libssl.log", "w");
ERR_print_errors_fp(error_file);
fclose(error_file);
fprintf(stdout,(char *)stringa);
fprintf(stdout,"\n");

问题是我在 stringa 中没有输出,我认为函数 RSA_padding_add.. 应该被初始化,但我在 openssl 站点的几个文档中找不到如何做。

谢谢

最佳答案

参见 http://www.openssl.org/docs/crypto/RSA_padding_add_PKCS1_type_1.html .在设置 string1 后尝试将 lSize 定义为 (int)strlen(string1)

编辑:

分配stringa。

unsigned char *stringa=malloc(num);

关于c - 带有 libssl 的 EMSA_PSS_ENCODE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2483630/

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