Qt HMAC hash 算法
2012-11-07 14:54:01 来源:WEB开发网 QString hmacSha1(QByteArray key, QByteArray baseString)
{
int blockSize = 64; // HMAC-SHA-1 block size, defined in SHA-1 standard
if (key.length() > blockSize) { // if key is longer than block size (64), reduce key length with SHA-1 compression
key = QCryptographicHash::hash(key, QCryptographicHash::Sha1);
}
QByteArray innerPadding(blockSize, char(0x36)); // initialize inner padding with char "6"
QByteArray outerPadding(blockSize, char(0x5c)); // initialize outer padding with char "/"
// ascii characters 0x36 ("6") and 0x5c ("/") are selected because they have large
// Hamming distance (http://en.wikipedia.org/wiki/Hamming_distance)
for (int i = 0; i < key.length(); i++) {
innerPadding[i] = innerPadding[i] ^ key.at(i); // XOR operation between every byte in key and innerpadding, of key length
outerPadding[i] = outerPadding[i] ^ key.at(i); // XOR operation between every byte in key and outerpadding, of key length
}
// result = hash ( outerPadding CONCAT hash ( innerPadding CONCAT baseString ) ).toBase64
QByteArray total = outerPadding;
QByteArray part = innerPadding;
part.append(baseString);
total.append(QCryptographicHash::hash(part, QCryptographicHash::Sha1));
QByteArray hashed = QCryptographicHash::hash(total, QCryptographicHash::Sha1);
return hashed.toBase64();
}
- ››QT中获取选中的radioButton的两种方法
- ››Qt HMAC hash 算法
- ››Qt中调用windows系统api在QComboBox中显示系统当前...
- ››Qt之实现360安全卫士主界面(三)
- ››HashSet的equals和hashCode重写问题
- ››Qt for Symbian S60开发环境全接触
- ››Qt for Symbian应用的开发
- ››Qt for Symbian怎样强制使用横屏或竖屏
- ››Qt与symbian特定格式类对象的转换
- ››Qt for symbian工程文件的一些特异写法
- ››QT for Symbian 环境搭建教材下载
- ››Qt for Symbian 入门之环境搭建
更多精彩
赞助商链接