c - 带有 libssl 的 EMSA_PSS_ENCODE

标签 c openssl libssl

您好,我正在尝试使用 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/

相关文章:

类似蛋糕的链表

c++ - boost Asio 和 OpenSSL 1.1.0

python - 如何提供 SWIG 的包含路径?

c++ - 链接错误 : Cannot find -l<path to library>

python - Python 在 Ubuntu 22.04 上找不到 libssl

c - 在未定义长度字符数组的超出范围上打印奇怪的字符

c - 使用 Eclipse 进行远程 C 调试

c - c中的快速排序算法实现

c - 是否可以使用 openssl 的 EVP api 用公钥解密

cocoa - 如何在 Lion 上将 libssl 与 Cocoa 一起使用?