3#include "RabbitCommonEncrypt.h"
7#if defined (HAVE_OPENSSL)
13static Q_LOGGING_CATEGORY(log,
"RabbitCommon.Encrypt")
15#define PASSWORD_LENGTH 16
17static const unsigned char Key[] =
19 0x56, 0x9a, 0x28, 0x12, 0xfa, 0x59, 0xa1, 0x58,
20 0x65, 0x7c, 0xc8, 0x92, 0x1a, 0x09, 0x10, 0x8a
23CEncrypt::CEncrypt(
const char* pszPassword)
25 SetPassword(pszPassword);
32int CEncrypt::SetPassword(
const char* pszPassword)
34 size_t nLen = PASSWORD_LENGTH;
35 if(nLen > strlen(pszPassword))
36 nLen = strlen(pszPassword);
38 m_szPassword.resize(PASSWORD_LENGTH, 0);
39 memcpy(&m_szPassword[0], Key, PASSWORD_LENGTH);
40 for(
int i = 0; i < nLen; i++)
42 m_szPassword[i] ^= pszPassword[i];
51 QString szIn = QString::fromStdString(std::string(pIn, inLen));
53 nRet =
Encode(szIn, szOut);
55 outLen = szOut.length();
56 *pOut =
new char[outLen];
57 memcpy(*pOut, szOut.data(), outLen);
64#if defined (HAVE_OPENSSL)
66 QByteArray in = szIn.toUtf8();
67 bool b = aes.ecb_encrypt(in, szOut,
68 QByteArray::fromStdString(m_szPassword));
76 szOut = szIn.toUtf8();
84#if defined (HAVE_OPENSSL)
87 bool b = aes.ecb_encrypt(szIn, out,
88 QByteArray::fromStdString(m_szPassword),
109 QByteArray in(pIn, inLen);
112 if(nRet)
return nRet;
113 outLen = out.length();
114 *pOut =
new char[outLen];
115 memcpy(*pOut, out.data(), outLen);
124 nRet =
Dencode(pIn, inLen, &pOut, nOutLen);
127 qCritical(log) <<
"Dencode error";
int Encode(const char *pIn, const int &inLen, char **pOut, int &outLen)
int Dencode(const char *pIn, const int &inLen, char **pOut, int &outLen)