4 #include <QCryptographicHash>
14 if (
key.length() > blockSize) {
15 key = QCryptographicHash::hash(
key, QCryptographicHash::Sha1);
18 QByteArray innerPadding(blockSize,
char(0x36));
19 QByteArray outerPadding(blockSize,
char(0x5c));
23 for (
int i = 0; i <
key.length(); i++) {
24 innerPadding[i] = innerPadding[i] ^
key.at(i);
25 outerPadding[i] = outerPadding[i] ^
key.at(i);
29 QByteArray total = outerPadding;
30 QByteArray part = innerPadding;
31 part.append(baseString);
32 total.append(QCryptographicHash::hash(part, QCryptographicHash::Sha1));
33 QByteArray hashed = QCryptographicHash::hash(total, QCryptographicHash::Sha1);
43 for (
const quint8 *ptr = encoded; count < bufSize && *ptr; ++ptr) {
46 if (ch ==
' ' || ch ==
'\t' || ch ==
'\r' || ch ==
'\n' || ch ==
'-') {
55 }
else if (ch ==
'1') {
57 }
else if (ch ==
'8') {
62 if ((ch >=
'A' && ch <=
'Z') || (ch >=
'a' && ch <=
'z')) {
64 }
else if (ch >=
'2' && ch <=
'7') {
74 result[count++] = buffer >> (bitsLeft - 8);
79 if (count < bufSize) {
80 result[count] =
'\000';
88 quint64 time = QDateTime::currentDateTime().toTime_t();
89 quint64 current = qToBigEndian(time / 30);
91 int secretLen = (
key.length() + 7) / 8 * 5;
93 int res =
base32_decode(
reinterpret_cast<const quint8 *
>(
key.constData()), secret, secretLen);
94 QByteArray hmac =
hmacSha1(QByteArray(
reinterpret_cast<const char *
>(secret), res), QByteArray((
char*)¤t,
sizeof(current)));
96 int offset = (hmac[hmac.length() - 1] & 0xf);
98 ((hmac[offset] & 0x7f) << 24)
99 | ((hmac[offset + 1] & 0xff) << 16)
100 | ((hmac[offset + 2] & 0xff) << 8)
101 | (hmac[offset + 3] & 0xff);
103 int digits = settings.value(
"2fadigits").toInt();
106 password = binary % 100000000;
107 return QString(
"%1").arg(password, 8, 10, QChar(
'0'));
108 }
else if (digits == 6) {
109 password = binary % 1000000;
110 return QString(
"%1").arg(password, 6, 10, QChar(
'0'));