Namespaces
Variants
Actions
Revision as of 11:59, 24 June 2011 by hamishwillee (Talk | contribs)

How to calculate hash for a text using QCryptographicHash in Qt

Jump to: navigation, search
{{{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

Platform Security
Capabilities: )

Article
Keywords: QCryptographicHash
Created: mind_freak (10 Apr 2009)
Last edited: hamishwillee (24 Jun 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

526 page views in the last 30 days.
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved