dmpserverdes.h 1.4 KB
/**************************************************************************
* file:              dmpserverdes.h

* Author:            qingxiongf
* Date:              2022-01-13 19:20:26
* Email:             qingxiongf@chinadci.com
* copyright:         广州城市信息研究所有限公司
***************************************************************************/

#ifndef __dmpserverdes_h__
#define __dmpserverdes_h__
#include "dmap_server.h"
#include <boost/filesystem.hpp>
#include <unordered_map>

#define ENCRYPTION_MODE 1
#define DECRYPTION_MODE 0

class SERVER_EXPORT DmpServerDes
{
public:
    typedef struct
    {
        unsigned char k[8];
        unsigned char c[4];
        unsigned char d[4];
    } key_set;

    bool Encrypt(unsigned char *source, unsigned char *des_key, unsigned char *destination);
    bool Decrypt(unsigned char *source, int length, unsigned char *key, unsigned char *destination);

   // static std::string RsaBase64Encrypt(const std::string &source, const char* key);
    static std::string DesBase64Decrypt(const std::string &source, const char* key);

private:
    void generate_key(unsigned char *key);
    void generate_sub_keys(unsigned char *main_key, key_set *key_sets);
    void process_message(unsigned char *message_piece, unsigned char *processed_piece, key_set *key_sets, int mode);
    void copyUChar(unsigned char *data_block, unsigned char *source, int loc, int num);
};

#endif // __dmpserverdes_h__