std::string getHash256(string infor, string key , bool flag ){
string mac, encoder , derived ;
/*一切是那么的神奇,前天加了这段代码就出错,所以注释了;
今天重测,又对了,想想还是注释了吧!先看下官方的说法先。*/
/*if( true ) {
HexDecoder decoder (new StringSink(derived));
decoder.Put((const byte*)key.data(), key.size());
decoder.MessageEnd();
}*/
try{
HMAC<SHA256> hmac((const byte*)key.data(), key.size());
StringSource(infor, true, new HashFilter(hmac, new StringSink(mac)));
}catch(const CryptoPP::Exception& e){
cerr << e.what() << endl;
exit(1);
}
encoder.clear();
StringSource(mac, true, new HexEncoder(new StringSink(encoder)));
transform(encoder.begin(), encoder.end(), encoder.begin(), ::tolower);
qDebug()<<"sign:"<<QString::fromStdString(encoder) ;
return encoder; //return HMAC
}
03_利用cryptopp写hmacsha256算法
最新推荐文章于 2024-08-22 13:54:42 发布