如何使用QCryptographicHash加密文本
文章信息
- 平 台:S60 3rd Edition FP1, S60 3rd Edition FP2, S60 5th Edition
- 设 备:S60 Emulator
- 类 别:Qt for Symbian, Garden release
- 关键字:QCryptographicHash,QByteArray
Contents |
简介
QCryptographicHash类提供生成加密哈希值的方法。
QCryptographicHash可用来生成二进制或文件数据的加密哈希值。目前支持三种算法:Md4, Md5, Sha1。
前提条件
一些相关函数
- 添加数据到加密哈希值
QByteArray string="Nokia"; hash->addData(string);
- 返回最终的哈希值
QByteArray string1=hash->result();
源代码
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->show();
return a.exec();
}
屏幕截图
更多参考:QCryptographicHash


(no comments yet)