QxOrm 1.4.9
C++ Object Relational Mapping library
Loading...
Searching...
No Matches
QxSimpleCrypt.h
Go to the documentation of this file.
1/*
2Copyright (c) 2011, Andre Somers
3All rights reserved.
4
5Redistribution and use in source and binary forms, with or without
6modification, are permitted provided that the following conditions are met:
7 * Redistributions of source code must retain the above copyright
8 notice, this list of conditions and the following disclaimer.
9 * Redistributions in binary form must reproduce the above copyright
10 notice, this list of conditions and the following disclaimer in the
11 documentation and/or other materials provided with the distribution.
12 * Neither the name of the Rathenau Instituut, Andre Somers nor the
13 names of its contributors may be used to endorse or promote products
14 derived from this software without specific prior written permission.
15
16THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19DISCLAIMED. IN NO EVENT SHALL ANDRE SOMERS BE LIABLE FOR ANY
20DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*/
27
28#ifndef _QX_SIMPLECRYPT_H_
29#define _QX_SIMPLECRYPT_H_
30
31#ifdef _MSC_VER
32#pragma once
33#endif
34
42#include <QtCore/qglobal.h>
43#include <QtCore/qstring.h>
44#include <QtCore/qvector.h>
45#include <QtCore/qbytearray.h>
46
47namespace qx {
48
74{
75
76public:
77
87
101
111
123 explicit QxSimpleCrypt(quint64 key);
124
128 void setKey(quint64 key);
132 bool hasKey() const {return !m_keyParts.isEmpty();}
133
140 void setCompressionMode(CompressionMode mode) {m_compressionMode = mode;}
144 CompressionMode compressionMode() const {return m_compressionMode;}
145
152 void setIntegrityProtectionMode(IntegrityProtectionMode mode) {m_protectionMode = mode;}
156 IntegrityProtectionMode integrityProtectionMode() const {return m_protectionMode;}
157
161 Error lastError() const {return m_lastError;}
162
168 QString encryptToString(const QString& plaintext) ;
174 QString encryptToString(QByteArray plaintext) ;
182 QByteArray encryptToByteArray(const QString& plaintext) ;
190 QByteArray encryptToByteArray(QByteArray plaintext) ;
191
199 QString decryptToString(const QString& cyphertext) ;
207 QByteArray decryptToByteArray(const QString& cyphertext) ;
215 QString decryptToString(QByteArray cypher) ;
223 QByteArray decryptToByteArray(QByteArray cypher) ;
224
225 // enum to describe options that have been used for the encryption. Currently only one, but
226 // that only leaves room for future extensions like adding a cryptographic hash...
227 enum CryptoFlag{CryptoFlagNone = 0,
228 CryptoFlagCompression = 0x01,
229 CryptoFlagChecksum = 0x02,
230 CryptoFlagHash = 0x04
231 };
233
234private:
235
236 void splitKey();
237
238 quint64 m_key;
239 QVector<char> m_keyParts;
243
244};
245
246} // namespace qx
247
248Q_DECLARE_OPERATORS_FOR_FLAGS(qx::QxSimpleCrypt::CryptoFlags)
249
250#endif // _QX_SIMPLECRYPT_H_
#define QX_DLL_EXPORT
Definition QxMacro.h:182
Simple encryption and decryption of strings and byte arrays.
QVector< char > m_keyParts
QString encryptToString(QByteArray plaintext)
QByteArray encryptToByteArray(QByteArray plaintext)
QString decryptToString(const QString &cyphertext)
QByteArray decryptToByteArray(QByteArray cypher)
QByteArray decryptToByteArray(const QString &cyphertext)
Q_DECLARE_FLAGS(CryptoFlags, CryptoFlag)
QString encryptToString(const QString &plaintext)
Error lastError() const
CompressionMode compressionMode() const
void setIntegrityProtectionMode(IntegrityProtectionMode mode)
CompressionMode m_compressionMode
bool hasKey() const
void setKey(quint64 key)
IntegrityProtectionMode integrityProtectionMode() const
QByteArray encryptToByteArray(const QString &plaintext)
QString decryptToString(QByteArray cypher)
void setCompressionMode(CompressionMode mode)
IntegrityProtectionMode m_protectionMode
QxSimpleCrypt(quint64 key)
Root namespace for all QxOrm library features.