How to calculate hash for a text using QCryptographicHash in Qt
valderind4
(Talk | contribs) m (moved How to Encrypt a text using QCryptographicHash to How to Encrypt a text using QCryptographicHash in Qt for Symbian: The new title new is more specific) |
|||
| Line 14: | Line 14: | ||
== Introduction == | == Introduction == | ||
| − | The QCryptographicHash class provides a way to generate cryptographic hashes. | + | The QCryptographicHash class provides a way to generate cryptographic hashes from binary or text data. |
| − | + | For more information, see Wikipedia on http://en.wikipedia.org/wiki/Cryptographic_hash_function | |
| − | |||
==Preconditions== | ==Preconditions== | ||
* [http://pepper.troll.no/s60prereleases/ Download the latest Qt for S60 distribution from Qt]. | * [http://pepper.troll.no/s60prereleases/ Download the latest Qt for S60 distribution from Qt]. | ||
| Line 26: | Line 25: | ||
== Some Related Function == | == Some Related Function == | ||
| − | *Adds the data to the cryptographic hash | + | *Adds the data to the cryptographic hash: |
| − | QByteArray string="Nokia"; | + | QByteArray string = "Nokia"; |
| − | + | QCryptographicHash hasher(QCryptographicHash::Sha1); | |
| + | hasher.addData(string); | ||
*Returns the final hash value. | *Returns the final hash value. | ||
| − | QByteArray string1= | + | QByteArray string1=hasher.result(); |
== Source Code == | == Source Code == | ||
| Line 39: | Line 39: | ||
===Main.cpp=== | ===Main.cpp=== | ||
<code cpp> | <code cpp> | ||
| − | |||
#include <QtGui/QApplication> | #include <QtGui/QApplication> | ||
#include "textcodec.h" | #include "textcodec.h" | ||
| − | #include<QWidget> | + | #include <QWidget> |
| − | #include<QHBoxLayout> | + | #include <QHBoxLayout> |
#include <QCryptographicHash> | #include <QCryptographicHash> | ||
| − | #include<QString> | + | #include <QString> |
| − | #include<QByteArray> | + | #include <QByteArray> |
| − | #include<QLabel> | + | #include <QLabel> |
| + | |||
int main(int argc, char *argv[]) | int main(int argc, char *argv[]) | ||
{ | { | ||
Revision as of 11:14, 28 September 2009
Article Metadata
Tested with
Devices(s): S60 Emulator
Compatibility
Platform(s): S60 3rd Edition FP1, S60 3rd Edition FP2, S60 5th Edition
Article
Keywords: QCryptographicHash,QByteArray
Created: (10 Apr 2009)
Last edited: User:Mgoetz
(28 Sep 2009)
Introduction
The QCryptographicHash class provides a way to generate cryptographic hashes from binary or text data.
For more information, see Wikipedia on http://en.wikipedia.org/wiki/Cryptographic_hash_function
Preconditions
- Download the latest Qt for S60 distribution from Qt.
- Install Qt for S60:Installing Qt on S60
- Check this link for installation guide: How to install the package.
- Go through this article: Getting started with Qt for S60
Some Related Function
- Adds the data to the cryptographic hash:
QByteArray string = "Nokia"; QCryptographicHash hasher(QCryptographicHash::Sha1); hasher.addData(string);
- Returns the final hash value.
QByteArray string1=hasher.result();
Source Code
Main.cpp
#include <QtGui/QApplication>
#include "textcodec.h"
#include <QWidget>
#include <QHBoxLayout>
#include <QCryptographicHash>
#include <QString>
#include <QByteArray>
#include <QLabel>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QWidget *win=new QWidget();
QHBoxLayout *lay=new QHBoxLayout();
QLabel *lbl=new QLabel();
QLabel *lbl1=new QLabel("Encrypted Text:");
lbl1->setBuddy(lbl);
QByteArray string="Nokia";
QCryptographicHash *hash=new QCryptographicHash(QCryptographicHash::Md4);
hash->addData(string);
QByteArray string1=hash->result();
lbl->setText(string1);
lay->addWidget(lbl1);
lay->addWidget(lbl);
win->setLayout(lay);
win->setStyleSheet("* { background-color:rgb(199,147,88); padding: 7px ; color:rgb(255,255,255)}");
win->showMaximized();
return a.exec();
}
ScreenShot
More About QCryptographicHash

