代码拉取完成,页面将自动刷新
#include "tts_encrypt.h"
#include "aes.h"
#include <QDebug>
#include <iostream>
using namespace std;
TTS_Encrypt::TTS_Encrypt(TTS_SettingObject so)
{
// init key and iv
memcpy(key, so.transport_enc_key.toLocal8Bit().constData(), 16);
memcpy(iv, so.transport_enc_iv.toLocal8Bit().constData(), 16);
moo.set_key(key);
moo.set_mode(MODE_CBC);
moo.set_iv(iv);
}
TTS_Encrypt::~TTS_Encrypt()
{
}
string TTS_Encrypt::encryptString(const string plaintext)
{
int plaintextSize = plaintext.size();
int encryptedDataSize = plaintextSize + 32; // alloc more space
string paddedtext;
int needToPadding = 16 - plaintextSize % 16;
int paddedSize = plaintextSize + needToPadding;
// 添加zeropadding
if (needToPadding != 0) {
string padding(needToPadding, '\x00');
paddedtext = plaintext + padding;
} else {
paddedtext = plaintext;
}
unsigned char* encryptedData = new unsigned char[encryptedDataSize];
memset(encryptedData, 0, encryptedDataSize);
int len = moo.Encrypt((unsigned char*) paddedtext.data(), paddedSize, encryptedData);
string estr;
estr.assign((char*)encryptedData, len);
delete[] encryptedData;
return estr;
}
string TTS_Encrypt::decryptString(const string enctext)
{
int encsize = enctext.size();
unsigned char* decdata = new unsigned char[encsize];
int len = moo.Decrypt( (unsigned char*) enctext.data(), encsize, decdata );
string dstr;
dstr.assign((char*)decdata, len);
delete[] decdata;
return dstr;
}
string TTS_Encrypt::toBase64(const string input)
{
QByteArray qb = QByteArray::fromStdString(input);
QByteArray qb64 = qb.toBase64();
string out(qb64.data(), qb64.size());
return out;
}
string TTS_Encrypt::fromBase64(const string input)
{
QByteArray qb64 = QByteArray::fromStdString(input);
QByteArray qb = qb64.fromBase64(qb64);
string out(qb.data(), qb.size());
return out;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。