密码散列

来源:互联网 发布:家庭理财记账软件 编辑:程序博客网 时间:2024/06/08 16:20

Qt给出了一些常用加密算法,本文以Md5为例。

main.cpp

#include <QCoreApplication>#include <QCryptographicHash>#include <QDebug>void encrypt(){    QByteArray byte_array;    byte_array.append("password");    QByteArray hash_byte_array = QCryptographicHash::hash(byte_array, QCryptographicHash::Md5);    QString md5 = hash_byte_array.toHex();    qDebug() << md5;}void encrypt2(){    QByteArray byte_array;    byte_array.append("password");    QCryptographicHash hash(QCryptographicHash::Md5);    hash.addData(byte_array);  //添加数据到加密哈希值    QByteArray result_byte_array = hash.result();  //返回最终的哈希值    QString md5 = result_byte_array.toHex();    qDebug() << md5;}int main(int argc, char *argv[]){    QCoreApplication a(argc, argv);    encrypt();    return a.exec();}
原创粉丝点击