QT 中实现HMAC-SHA1
来源:互联网 发布:java调dll内存泄露 编辑:程序博客网 时间:2024/05/22 14:14
实现函数:
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 "quot; // ascii characters 0x36 ("6") and 0x5c ("quot;) 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();}
转自:QTWIKI
也有人稍有不同的做法:
Qt 实现 HMAC_SHA1 哈希算法
阅读全文
1 0
- QT 中实现HMAC-SHA1
- Qt 中实现 hmac Sha1 加密并以 base64编码输出
- OAuth认证的 HMAC-SHA1签署 实现
- HMAC-SHA1各语言版本实现
- HMAC-SHA1 BASE64编码 java源代码实现
- HMAC-SHA1各语言版本实现
- Java HMAC-SHA1加密算法的实现
- 在Android中生成HMAC-SHA1 签名
- php中使用hash_hmac函数实现HMAC-SHA1签名算法的来龙去脉
- php中使用hash_hmac函数实现HMAC-SHA1签名算法的来龙去脉
- golang 中的md5 、hmac、sha1算法的简单实现
- 实现接口访问的HMAC-SHA1签名算法
- HMAC-SHA1 java版
- HMAC-SHA1 java版
- iOS HMAC SHA1
- hmac使用sha1
- hmac-sha1算法
- php sha1 hmac
- SVM入门(六)线性分类器的求解——问题的转化,直观角度
- curl请求https POST和GET方法
- HDU 2859
- 线段树模板
- android 利用cmdline,将参数从preloader传递到kernel
- QT 中实现HMAC-SHA1
- Apache基本配置
- HDU 6092 Rikka with Subset
- 使用Python手动获取Windows10 聚焦壁纸
- Hibernate介绍
- android RXJava2.0(一)
- 股市基础
- Go 并发concurrency 学习笔记
- 网易机器学习笔试题2