gpt4 book ai didi

c++ - libsodium crypto_sign_open 返回添加一些字符的未签名消息

转载 作者:行者123 更新时间:2023-11-30 03:17:39 24 4
gpt4 key购买 nike

在我的 C++ 项目中,我使用 libsodium 库来创建和验证消息的签名。

为了验证签名,我以这种方式使用 libsodium crypto_sign_open 函数

bool Signature::signatureVerification(const char* content, unsigned char* unsigned_message)
{
bool verified;

unsigned long long unsigned_message_len;

if (crypto_sign_open(unsigned_message, &unsigned_message_len, (const unsigned char *)content, signed_message_len, pk) != 0)
{
verified = false;
std::cout << "incorrect signature " << std::endl;
}
else{
verified = true;
}
//print variable unsigned_message
return verified;
}

如果我“打印”变量 unsigned_message,我会得到未签名的消息,后面跟着一些来自签名的字符。例如,如果消息是“你好”,在签名验证后我得到“你好...*”。

现在我使用消息的原始长度(存储在变量 unsigned_message_len 中)截断函数返回的消息来“解决”这个问题。

可能是什么问题?为什么在 unsigned_message 变量中有一些额外的字符,而不仅仅是原始消息?

谢谢

最佳答案

那是因为您没有空终止符,请尝试在 unsigned_message 之后添加 + 1,无论它是从哪里打印的。您的代码显然会在文本之后打印出随机字符,因为它是“未签名”的,这意味着它没有带符号的数据位值。 + 1 应该终止随机符号。

关于c++ - libsodium crypto_sign_open 返回添加一些字符的未签名消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55317493/

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