// // Created by xajhu on 2021/7/2 0002. // #ifndef DAEMON_AGENT_CRYPTO_CRYPTO_H #define DAEMON_AGENT_CRYPTO_CRYPTO_H #ifdef __cplusplus extern "C" { #endif typedef enum { DES3_ECB_PKCS7PADDING = 0, DES3_CBC_PKCS7PADDING, DES3_OFB_PKCS7PADDING, AES128_ECB_PKCS7PADDING, AES128_ECB_PKCS7PADDING_SHA1PRNG, AES128_CBC_PKCS7PADDING, AES128_OFB_PKCS7PADDING, AES192_ECB_PKCS7PADDING, AES192_CBC_PKCS7PADDING, AES192_OFB_PKCS7PADDING, AES256_ECB_PKCS7PADDING, AES256_CBC_PKCS7PADDING, AES256_OFB_PKCS7PADDING, } AES_TYPE; typedef enum { CRYPTO_AES_ENCRYPT = 0, CRYPTO_AES_DECRYPT, CRYPTO_BASE64_ENCODE, CRYPTO_BASE64_DECODE, CRYPTO_MD5_FILE, } CRYPTO_TYPE; typedef enum { HASH_TYPE_MD5 = 0, HASH_TYPE_SHA1 = 1, HASH_TYPE_SHA256 = 2, } HASH_TYPE; typedef void (*on_evp_crypto)(CRYPTO_TYPE type, const unsigned char *pData, unsigned int iSize, const unsigned char *pSrcData, int iError); //***************************************************** // AES //***************************************************** int symmetric_encrypto(AES_TYPE algorithmType, unsigned char *pInBuf, unsigned int inSize, unsigned char **pOutBuf, int *pOutSize, const char *pKey); int symmetric_decrypto(AES_TYPE algorithmType, unsigned char *pInBuf, unsigned int inSize, unsigned char **pOutBuf, int *pOutSize, const char *pKey); //***************************************************** // BASE64 //***************************************************** #if 0 const char *base64_encode(unsigned char *pSrc, unsigned int sLen); unsigned char * base64_decode(const char *pBase64); #endif const char *base64_encode(unsigned char *pSrc, unsigned int sLen); unsigned char *base64_decode(const char *pBase64, unsigned int *pOutSize); //***************************************************** // MD5 //***************************************************** int hash_digest_file(HASH_TYPE hashType, const char *pFileName, char **pHashValue); int hash_digest_mem(HASH_TYPE hashType, const unsigned char *pBuf, unsigned int iBufLen, unsigned char **pHashValue, unsigned int *pOutSize); //***************************************************** // Async Engine //***************************************************** int evp_add_crypto_task(CRYPTO_TYPE type, unsigned char *pInBuf, unsigned int iSize, unsigned char *pOutBuf, char *pKey, on_evp_crypto onEvpCryptCb); void evp_system_init(void); #ifdef __cplusplus } #endif #endif //DAEMON_AGENT_CRYPTO_CRYPTO_H