gmc999452122415 2024-08-20 23:24 采纳率: 0%
浏览 15

为什么gmssl安装编译完测试数据后却报错


/*
 *  Copyright 2014-2022 The GmSSL Project. All Rights Reserved.
 *
 *  Licensed under the Apache License, Version 2.0 (the License); you may
 *  not use this file except in compliance with the License.
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 */

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <gmssl/sm2.h>
#include <gmssl/error.h>


int main(void)
{
    SM2_KEY sm2_key;
    SM2_KEY pub_key;
    unsigned char plaintext[SM2_MAX_PLAINTEXT_SIZE];
    unsigned char ciphertext[SM2_MAX_CIPHERTEXT_SIZE];
    size_t len;

    sm2_key_generate(&sm2_key);
    memcpy(&pub_key, &sm2_key, sizeof(SM2_POINT));

    sm2_key_print(stdout, 0, 0, "SM2Key", &sm2_key);

    sm2_encrypt(&pub_key, (uint8_t*)"hello world", strlen("hello world"), ciphertext, &len);
    format_bytes(stdout, 0, 0, "ciphertext", ciphertext, len);

    if (sm2_decrypt(&sm2_key, ciphertext, len, plaintext, &len) != 1) {
        fprintf(stderr, "error\n");
        return 1;
    }
    plaintext[len] = 0;
    printf("plaintext: %s\n", plaintext);

    return 0;
}

代码如上,但是点击调试后却是图下这个样子

img


配置我是按照这篇配置的,前面都很顺利,就是最后没有成功,想问一下为什么,谢谢https://blog.csdn.net/D_Flash/article/details/139914573?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522172416631216800186557046%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fall.%2522%257D&request_id=172416631216800186557046&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~first_rank_ecpm_v1~times_rank-2-139914573-null-null.142^v100^pc_search_result_base4&utm_term=%E6%96%B0%E7%89%88GMSSL%E4%B8%8B%E8%BD%BD%E7%BC%96%E8%AF%91&spm=1018.2226.3001.4187

  • 写回答

1条回答 默认 最新

  • 吃不了席 2024-08-20 23:25
    关注

    以下回复参考:皆我百晓生券券喵儿等免费微信小程序作答:

    根据您提供的错误信息,问题出在sm2_decrypt函数调用失败。可能的原因有以下几点:

    1. 密钥不匹配:解密时使用的私钥与加密时使用的公钥不匹配。请确保您在加密和解密过程中使用了正确的密钥对。

    2. 数据格式错误:输入的数据格式可能不符合SM2加密算法的要求。请检查输入数据的格式是否正确。

    3. GmSSL库配置问题:可能是GmSSL库的配置或编译过程出现问题。请检查您的GmSSL库是否已正确配置和编译。

    为了解决这个问题,您可以尝试以下步骤:

    1. 检查密钥对是否正确:确保加密时使用的公钥与解密时使用的私钥是匹配的。

    2. 检查输入数据格式:确保输入的数据符合SM2加密算法的要求。

    3. 重新配置和编译GmSSL库:按照官方文档重新配置和编译GmSSL库,确保库文件正确无误。

    如果问题仍然存在,建议您查阅GmSSL官方文档或在相关社区寻求帮助。

    评论

报告相同问题?

问题事件

  • 创建了问题 8月20日