wirelessgateway/secure/SH_Secure.hpp

53 lines
2.0 KiB
C++
Raw Normal View History

2021-09-18 13:45:24 +08:00
#ifndef _WL_SECUREAPI_H_
#define _WL_SECUREAPI_H_
#include <string>
#include "../utility/SH_MySingleton.hpp"
typedef unsigned char u_char;
typedef unsigned long u_long;
/************************
*
*
*
*************************/
class Secure : public MySingleton<Secure>{
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];
};
#endif