| 329 | |
| 330 | |
| 331 | QString GenerateHash(const QString &algorithm, int length, const QString &inputString) |
| 332 | { |
| 333 | QCryptographicHash::Algorithm hashAlgo; |
| 334 | |
| 335 | if (algorithm == "sha1") { |
| 336 | hashAlgo = QCryptographicHash::Sha1; |
| 337 | } else { |
| 338 | hashAlgo = QCryptographicHash::Md5; |
| 339 | } |
| 340 | |
| 341 | QByteArray hash = QCryptographicHash::hash(inputString.toUtf8(), hashAlgo).toHex(); |
| 342 | if (length > hash.size()) { |
| 343 | length = hash.size(); |
| 344 | } |
| 345 | return QString(hash.left(length)); |
| 346 | } |