WLG/utility/secure.hpp

55 lines
2.1 KiB
C++
Raw Normal View History

2024-10-23 09:22:06 +08:00
#ifndef SECURE_HPP_
#define SECURE_HPP_
2024-10-22 19:04:25 +08:00
#include <string>
2024-10-22 20:56:21 +08:00
#include <boost/container/detail/singleton.hpp>
2024-10-22 19:04:25 +08:00
typedef unsigned char u_char;
typedef unsigned long u_long;
/************************
*
*
*
*************************/
2024-10-22 20:56:21 +08:00
class Secure {
2024-10-22 19:04:25 +08:00
public:
Secure();
virtual ~Secure();
void GetKey(char* pKey, std::string pImeiId); //获取手机KEY
void GetKey(std::string gwmac); //获取连接云服务器的KEY
char* Base64Encode(const unsigned char* bindata, char* base65, int binlength);
int Base64Decode(const char* base64, unsigned char* bindata);
int ZigbeeDataEncrypt(char* pData); // zigbee数据加密
int ZigbeeDataEncrypt_Hex(char* pData, int len); // zigbee数据加密 HEX格式
void ZigbeeDataDecrypt(char* pData, int pLen); // zigbee数据解密
int NetDataEncrypt(char* pMing, char* pMi, char* pKey); //网络数据加密
int NetDataDecrypt(char* pMing, char* pMi, char* pKey); //网络数据解密
int NetDataDecrypt(char* pMing, char* pMi, int pLen, char* pKey);
char* Md5Sum(const char* filename);
int Encrypt(u_char* plaintext, u_char* expectText, int c_len, u_char* key);
int Decrypt(u_char* expectText, u_char* currentText, int c_len, u_char* key);
void BteaEncrypt(u_char* buf, u_char len);
void BteaDecrpyt(u_char* buf, u_char len);
char* FnMD5CACL(u_char* buf, int len);
enum { KEYLen = 16 };
char KEY[KEYLen];
typedef struct {
int nr; /*!< number of rounds */
unsigned int* rk; /*!< AES round keys */
unsigned int buf[68]; /*!< unaligned data */
} aes_context;
void aes_setkey_enc(aes_context* ctx, const unsigned char* key, int keysize);
void aes_setkey_dec(aes_context* ctx, const unsigned char* key, int keysize);
unsigned char* aes_crypt_ecb(aes_context* ctx, int mode, const unsigned char* input, int slen, int* dlen);
private:
char result[33];
};
2024-10-22 20:56:21 +08:00
typedef boost::container::dtl::singleton_default<Secure> secure;
2024-10-23 09:22:06 +08:00
#endif // SECURE_HPP_