1

您好我正在尝试使用 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 站点的少数文档中找不到如何做。

谢谢

4

1 回答 1

0

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

编辑:

分配字符串。

unsigned char *stringa=malloc(num);

于 2010-03-20T16:55:29.317 回答