Adding AES128 encryption/decryption which works both with gcrypt and openssl. This can be used for encryption of player's cards (not implemented yet).

This commit is contained in:
lotodore
2010-08-29 15:39:46 +00:00
parent 698432279f
commit 073ef0ea01
2 changed files with 125 additions and 38 deletions
+8 -1
View File
@@ -27,6 +27,9 @@
#define MD5_DATA_SIZE 16
#define SHA1_DATA_SIZE 20
#define AES_BLOCK_SIZE 16
#define ADD_PADDING(x) ((((x) + 15) >> 4) << 4)
class HashBuf
{
public:
@@ -76,7 +79,11 @@ public:
static bool MD5Sum(const std::string &fileName, MD5Buf &buf);
static bool SHA1Hash(const unsigned char *data, unsigned dataSize, SHA1Buf &buf);
static bool HMACSha1(const unsigned char *keyData, unsigned keySize, const unsigned char *plainData, unsigned plainSize, SHA1Buf &buf);
static bool AES128Encrypt(const unsigned char *keyData, unsigned keySize, const unsigned char *plainData, unsigned plainSize, std::vector<unsigned char> &outCipher);
static bool AES128Encrypt(const unsigned char *keyData, unsigned keySize, const std::string &plainStr, std::vector<unsigned char> &outCipher);
static bool AES128Decrypt(const unsigned char *keyData, unsigned keySize, const unsigned char *cipher, unsigned cipherSize, std::string &outPlain);
private:
static void BytesToKey(const unsigned char *keyData, unsigned keySize, unsigned char *key, unsigned char *iv);
};
#endif