//--------------------------------------------------------------------------- #ifndef TWinCryptFH #define TWinCryptFH //--------------------------------------------------------------------------- #include #include #include //--------------------------------------------------------------------------- //https://www.experts-exchange.com/articles/1193/Easy-String-Encryption-Using-CryptoAPI-in-C.html class TWinCrypt { public: TWinCrypt(); virtual ~TWinCrypt(); private: HCRYPTPROV FProv; HCRYPTHASH FHash; HCRYPTKEY FKey; bool FOk; DWORD FLastErr; std::string FErrMsg; char *FDefaultKeyRaw; public: bool SetKey(LPCSTR szKey, LPCSTR szSalt=NULL); bool EncryptDecrypt(BYTE* pData, DWORD* dwDataLen, LPCSTR pKey, bool fEncrypt); std::string EncryptStrToHex(LPCSTR szText, LPCSTR pszKey = 0, LPCSTR pszSalt = 0); std::string EncodeToHex(BYTE* p, int nLen); std::string DecryptStrFromHex(LPCSTR szHex, LPCSTR pszKey = 0, LPCSTR pszSalt = 0); int DecodeFromHex(LPCSTR pSrc, BYTE* pDest, int nBufLen); }; //--------------------------------------------------------------------------- #endif