我向通义灵码提问需要一个mbedtls库的RSA公钥验签示例代码,通义灵码输出到公钥数据部分卡死,这是什么问题呢?
输出代码如下:
#include <stdio.h>
#include <string.h>
#include <mbedtls/platform.h>
#include <mbedtls/debug.h>
#include <mbedtls/entropy.h>
#include <mbedtls/ctr_drbg.h>
#include <mbedtls/pk.h>
#include <mbedtls/md.h>
#include <mbedtls/rsa.h>
int main() {
// 初始化 Mbed TLS 库
mbedtls_platform_setup(NULL);
// 创建熵源和随机数生成器上下文
mbedtls_entropy_context entropy;
mbedtls_ctr_drbg_context ctr_drbg;
mbedtls_entropy_init(&entropy);
mbedtls_ctr_drbg_init(&ctr_drbg);
if (mbedtls_ctr_drbg_seed(&ctr_drbg, mbedtls_entropy_func, &entropy, (const unsigned char *) "my seed", 9)) {
printf("Failed to seed ctr_drbg\n");
goto exit;
}
// 创建公钥上下文
mbedtls_pk_context pk;
mbedtls_pk_init(&pk);
// 公钥数据(PEM 格式)
const char *public_key_pem =
"-----BEGIN PUBLIC KEY-----\n"
"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA77oXvZ+R5WJUHqXsDfLl\n"
"uFyNz3B3t55b45eOQa2r12345678901234567890123456789012345678901234\n"
"5678901234567890123456789012345678901234567890123456789012345678\n"
"901234567890123456789012345678901234567890123456789012345678901\n"
"234567890123456789012345678901234567890123456789012345678901234\n"
"5678901234567890123456789012345678901234567890123456789012345678\n"
"901234567890123456789012345678901234567890123456789012345678901\n"
"234567890123456789012345678901234567890123456789012345678901234\n"
"5678901234567890123456789012345678901234567890123456789012345678\n"
"901234567890123456789012345678901234567890123456789012345678901\n"
"234567890123456789012345678901234567890123456789012345678901234\n"
"5678901234567890123456789012345678901234567890123456789012345678\n"
"901234567890123456789012345678901234567890123456789012345678901\n"
"234567890123456789012345678901234567890123456789012345678901234\n"
"5678901234567890123456789012345678901234567890123456789012345678\n"
"901234567890123456789012345678901234567890123456789012345678901\n"
"234567890123456789012345678901234567890123456789012345678901234\n"
"5678901234567890123456789012345678901234567890123456789012345678\n"
"901234567890123456789012345678901234567890123456789012345678901\n"
"234567890123456789012345678901234567890123456789012345678901234\n"
"5678901234567890123456789012345678901234567890123456789012345678\n"
"901234567890123456789012345678901234567890123456789012345678901\n"
"234567890123456789012345678901234567890123456789012345678901234\n"
"5678901234567890123456789012345678901234567890123456789012345678\n"
"901234567890123456789012345678901234567890123456789012345678901\n"
"234567890123456789012345678901234
,公钥数据在最后被截断了。一个有效的 PEM 格式的公钥应该以 "-----END PUBLIC KEY-----\n" 结尾。如果公钥数据不完整,尝试解析它时将导致程序失败。
解析问题:如果公钥格式不正确或者在解析过程中遇到错误,也可能导致程序异常。
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。