In my C++ project I'm using libsodium library to create and verify the signature of a message.
To verify the signature I'm using the libsodium crypto_sign_open
function in this way
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;
}
If I "print" the variable unsigned_message
I get the unsigned message followed by some characters coming from the signature. For example, if the message is 'hello', after the signature verification I get 'hello�*�'.
For now I "solved" the issue using the original length of the message (stored in the variable unsigned_message_len
) to truncate the message returned by the function.
What could be the issue? Why in the unsigned_message
variable there are some additional characters and not only the original message?
Thanks