AES_PKCS7.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // 文 件 名:AES.h
  3. // 描 述:AES加密算法
  4. // 创 建 人:Liangbofu
  5. // 创建日期:2009-07-17
  6. ///////////////////////////////////////////////////////////////////////////////
  7. #ifndef __AES_H
  8. #define __AES_H
  9. #ifdef __cplusplus
  10. extern "C" {
  11. #endif
  12. // 以bit为单位的密钥长度,只能为 128,192 和 256 三种
  13. #define AES_KEY_LENGTH 128
  14. // 加解密模式
  15. #define AES_MODE_ECB 0 // 电子密码本模式(一般模式)
  16. #define AES_MODE_CBC 1 // 密码分组链接模式
  17. #define AES_MODE AES_MODE_CBC
  18. ///////////////////////////////////////////////////////////////////////////////
  19. // 函数名: AES_Init
  20. // 描述: 初始化,在此执行扩展密钥操作。
  21. // 输入参数: pKey -- 原始密钥,其长度必须为 AES_KEY_LENGTH/8 字节。
  22. // 输出参数: 无。
  23. // 返回值: 无。
  24. ///////////////////////////////////////////////////////////////////////////////
  25. void AES_Init(const void *pKey);
  26. //////////////////////////////////////////////////////////////////////////
  27. // 函数名: AES_Encrypt
  28. // 描述: 加密数据
  29. // 输入参数: pPlainText -- 明文,即需加密的数据,其长度为nDataLen字节。
  30. // nDataLen -- 数据长度,以字节为单位,必须为AES_KEY_LENGTH/8的整倍数。
  31. // pIV -- 初始化向量,如果使用ECB模式,可设为NULL。
  32. // 输出参数: pCipherText -- 密文,即由明文加密后的数据,可以与pPlainText相同。
  33. // 返回值: 无。
  34. //////////////////////////////////////////////////////////////////////////
  35. void AES_Encrypt(const unsigned char *pPlainText, unsigned char *pCipherText,
  36. unsigned int nDataLen, const unsigned char *pIV);
  37. //////////////////////////////////////////////////////////////////////////
  38. // 函数名: AES_Decrypt
  39. // 描述: 解密数据
  40. // 输入参数: pCipherText -- 密文,即需解密的数据,其长度为nDataLen字节。
  41. // nDataLen -- 数据长度,以字节为单位,必须为AES_KEY_LENGTH/8的整倍数。
  42. // pIV -- 初始化向量,如果使用ECB模式,可设为NULL。
  43. // 输出参数: pPlainText -- 明文,即由密文解密后的数据,可以与pCipherText相同。
  44. // 返回值: 无。
  45. //////////////////////////////////////////////////////////////////////////
  46. void AES_Decrypt(unsigned char *pPlainText, const unsigned char *pCipherText,
  47. unsigned int nDataLen, const unsigned char *pIV);
  48. //对数据进行解密操作,成功返回1,失败返回0
  49. unsigned char app_data_encode_aes(char *input, char *output, unsigned short *slen);
  50. unsigned char app_data_decode_aes(unsigned char *input, char *output, unsigned short *slen);
  51. unsigned int AES_Encrypt_PKCS7(const unsigned char *pPlainText, unsigned char *pCipherText,
  52. unsigned int nDataLen, const unsigned char *pIV);
  53. unsigned int AES_get_length(unsigned int length);
  54. void AES_free(unsigned char* p);
  55. #ifdef __cplusplus
  56. }
  57. #endif
  58. #endif // __AES_H