×
Namespaces

Variants
Actions
(Difference between revisions)

How to calculate hash for a text using QCryptographicHash in Qt

From Nokia Developer Wiki
Jump to: navigation, search
kiran10182 (Talk | contribs)
hamishwillee (Talk | contribs)
m (Add Abstract. Point to correct Qt SDK)
Line 1: Line 1:
[[Category:Qt]]
+
[[Category:Qt]][[Category:UI]]
{{ReviewerApproved}}
+
{{ReviewerApproved|timestamp=20090928}}
 
+
__NOTOC__
+
__NOEDITSECTION__
+
 
{{CodeSnippet
 
{{CodeSnippet
 
|id=...
 
|id=...
 
|platform=S60 3rd Edition FP1, S60 3rd Edition FP2, S60 5th Edition  
 
|platform=S60 3rd Edition FP1, S60 3rd Edition FP2, S60 5th Edition  
 
|devices= S60 Emulator
 
|devices= S60 Emulator
|category=Qt for S60
+
|category=Qt
 
|subcategory=UI
 
|subcategory=UI
 
|creationdate=10 April 2009
 
|creationdate=10 April 2009
|keywords=QCryptographicHash,QByteArray
+
|keywords=QCryptographicHash
 
}}
 
}}
  
 
== Introduction ==
 
== Introduction ==
The QCryptographicHash class provides a way to generate cryptographic hashes from binary or text data.
+
{{Abstract|visible=true|This example shows how to encrypt text using a [http://doc.qt.nokia.com/stable/qcryptographichash.html QCryptographicHash]. }}
 
+
For more information, see Wikipedia on http://en.wikipedia.org/wiki/Cryptographic_hash_function
+
  
 
==Preconditions==
 
==Preconditions==
  
* Download and Install latest version [[Qt for Symbian - Installation packages]] which has links on how to install the latest version
+
* Download and install the [[Qt SDK]]
  
  
Line 70: Line 65:
  
 
==ScreenShot==
 
==ScreenShot==
More About [http://qt.nokia.com/doc/4.5/qcryptographichash.html QCryptographicHash]
 
  
[[Image:Crypto.JPG]][[Category:Code Examples]]
+
[[Image:Crypto.JPG]]
 +
 
 +
[[Category:Code Examples]]

Revision as of 01:57, 26 April 2011

{{{width}}}
28 Sep
2009
Article Metadata
Tested with
Devices(s): S60 Emulator
Compatibility
Platform(s): S60 3rd Edition FP1, S60 3rd Edition FP2, S60 5th Edition
Symbian
Article
Keywords: QCryptographicHash
Created: (10 Apr 2009)
Last edited: hamishwillee (26 Apr 2011)

Contents

Introduction

This example shows how to encrypt text using a QCryptographicHash.

Preconditions

  • Download and install the Qt SDK


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 <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); // TODO: use e.g. toHex or toBase64
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

Crypto.JPG

280 page views in the last 30 days.