Qt封装的RSA加解密,AES加解密类

Qt封装的RSA加解密,AES加解密类

#pragma execution_character_set("utf-8")
#ifndef YCRSA_H
#define YCRSA_H
#include <QDebug>
#ifdef Q_OS_WIN
#include <openssl/rsa.h>
#include <openssl/pem.h>
#include <openssl/err.h>
#include <openssl/aes.h>
#else
#include </usr/local/include/openssl/rsa.h>
#include </usr/local/include/openssl/pem.h>
#include </usr/local/include/openssl/err.h>
#include </usr/local/include/openssl/aes.h>
#endif
// define rsa public key
#define BEGIN_RSA_PUBLIC_KEY    "BEGIN RSA PUBLIC KEY"
#define BEGIN_PUBLIC_KEY        "BEGIN PUBLIC KEY"
#define KEY_LENGTH              1024                        // 密钥长度

class YCRsa
{
public:
static bool createRsaKey (QString& strPublicKey, QString& strPrivateKey);
static QString privateEncryptBase64 (const QString& strClearData, const QString& strPriKey, const QByteArray codec = "");
static QString publicDecryptBase64 (const QString& strDecryptData, const QString& strPubKey, const QByteArray codec = "");
static QString publicEncryptBase64 (const QString& strClearData, const QString& strPubKey, const QByteArray codec = "");
static QString privateDecryptBase64 (const QString& strDecryptData, const QString& strPriKey, const QByteArray codec = "");

static std::string encryptAES( const std::string &password, const std::string &data);
//传入utf8 data
static QString encryptAESBase64( const QString &password, const QString &data);
//data可以传入QByteArray的gbk gb2312等,返回base64
static QString encryptGbkAESBase64( const QString &password, const QByteArray &data);
static std::string decryptAES( const std::string &strPassword, const std::string &strData);
static QString decryptAESBase64( const QString &strPassword, const QString &strData);
//返回的QByteArray做编码转换处理,可以得到对应编码
static QByteArray decryptGbkAESBase64( const QString &strPassword, const QString &strData);
};
#endif // RSA_H

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值