寻求使用 OpenSSL 的 HMAC 函数的一些帮助。目前此功能在 HMAC 调用上失败。仅适用于 OSX。 Linux 和 Windows 操作系统都工作正常。
QString tradingDialog::HMAC_SHA512_SIGNER(QString UrlToSign, QString Secret){
QString retval = "";
QByteArray byteArray = UrlToSign.toUtf8();
const char* URL = byteArray.constData();
QByteArray byteArrayB = Secret.toUtf8();
const char* Secretkey = byteArrayB.constData();
const EVP_MD *md = EVP_sha512();
unsigned char* digest = NULL;
// Be careful of the length of string with the choosen hash engine. SHA1 produces a 20-byte hash value which rendered as 40 characters.
// Change the length accordingly with your choosen hash engine
char mdString[129] = { 0 };
// Using sha512 hash engine here.
digest = HMAC(md, Secretkey, strlen( Secretkey), (unsigned char*) URL, strlen( URL), NULL, NULL);
for(int i = 0; i < 64; i++){
sprintf(&mdString[i*2], "%02x", (unsigned int)digest[i]);
}
retval = mdString;
return retval;
}
最佳答案
你没有说 osx 上的问题是什么,但看起来你没有终止 mdString
,所以尝试将其更改为
char mdString[129] = { 0 };
您链接到的崩溃日志显示您的应用程序正在中止,因为堆栈已损坏(我假设这发生在退出时)。
我想说最终的sprintf
导致了这个问题,因为它在mdString
数组末尾添加了一个nul字节。尝试上面的修改,看看是否有帮助。
这应该在所有平台上崩溃,但我猜你很“幸运”。
关于c++ - Mountain lion OSX 10.8.3 EXC_CRASH 上的 HMAC,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33979148/