stm32 AES動態(tài)加密算法,大家可以下載進行測試
1、該算法工程是基于Keil5環(huán)境進行編譯下載,單片機型號是stm32f030c8.
2、打開文件夾Project,雙擊"16BytesAES.uvprojx",即可打開工程。
3、如果不想利用該工程,只需要拷貝文件夾USER下的AES.c,AES.h,main.c到自己的工程,修改頭文件即可。
stm32單片機源程序如下:
- /**
- ******************************************************************************
- * @file GPIO/GPIO_IOToggle/main.c
- * @author MCD Application Team
- * @version V1.4.0
- * @brief Main program body
- ******************************************************************************
- * @attention
- *
- * <h2><center>© COPYRIGHT 2014 STMicroelectronics</center></h2>
- *
- * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
- * You may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- * http://www.st.com/software_license_agreement_liberty_v2
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************************
- */
- /* Includes ------------------------------------------------------------------*/
- #include "stm32f0xx.h"
- #include "stm32f0xx_conf.h"
- #include "stdio.h"
- #include "stdlib.h"
- #include "Mcu_config.h"
- #include "Serial.h"
- #include "AES.h"
- /** @addtogroup STM32F0xx_StdPeriph_Examples
- * @{
- */
- /** @addtogroup GPIO_IOToggle
- * @{
- */
- /* Private typedef -----------------------------------------------------------*/
- /* Private define ------------------------------------------------------------*/
- #ifdef __GNUC__
- /* With GCC/RAISONANCE, small printf (option LD Linker->Libraries->Small printf
- set to 'Yes') calls __io_putchar() */
- #define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
- #else
- #define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
- #endif /* __GNUC__ */
-
-
-
- /* Private macro -------------------------------------------------------------*/
- /* Private variables ---------------------------------------------------------*/
- /* Private function prototypes -----------------------------------------------*/
- /* Private functions ---------------------------------------------------------*/
- /**
- * @brief Main program.
- * @param None
- * @retval None
- */
- char expressText[1024]; //存放待加密的明文數(shù)據(jù),具體緩存大小根據(jù)用戶待加密數(shù)據(jù)長度自己任意修改
- char cipherText[1024];//存放已加密的密文數(shù)據(jù),具體緩存大小根據(jù)用戶解密后的數(shù)據(jù)長度自己任意修改
- char aesKey[16];//加解密的密鑰,注意:此算法只適用于AES16位密鑰加解密,不適用于32位密鑰加解密
- //該AES算法加密方式為:AES-128bit/ECB/PKCS5Padding
- /*
- 歡迎加入
- 二手開發(fā)板供求交易群 68936520
- arm交流學習群 324753668
- stm32交流學習群 227043677
- */
- int main(void)
- {
- MCU_Init();
-
- delay_1ms(2000);
-
- memcpy(aesKey , "1uweiIDAS7awOas8" , 16); //AES加密密鑰,16字節(jié)(128bit)
-
- memset(expressText ,0 ,1024);
- memset(cipherText , 0 ,1024);
- strcpy(expressText , "Hello!!!Are you ready???");
- AES_Encrypt(expressText , cipherText , aesKey); //use aesKey encrypt
-
- memset(expressText ,0 ,1024);
- AES_Decrypt(expressText , cipherText , aesKey);//use aesKey decrypt
- while(1)
- {
- delay_1ms(2000);
- }
-
- }
- /**
- * @brief Retargets the C library printf function to the USART.
- * @param None
- * @retval None
- */
- PUTCHAR_PROTOTYPE
- {
- /* Place your implementation of fputc here */
- /* e.g. write a character to the USART */
-
- USART_SendData(USART2, (uint8_t) ch);
- /* Loop until transmit data register is empty */
- while (USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET)
- {}
- return ch;
- }
- #ifdef USE_FULL_ASSERT
- /**
- * @brief Reports the name of the source file and the source line number
- * where the assert_param error has occurred.
- * @param file: pointer to the source file name
- * @param line: assert_param error line source number
- * @retval None
- */
- void assert_failed(uint8_t* file, uint32_t line)
- {
- /* User can add his own implementation to report the file name and line number,
- ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
- /* Infinite loop */
- while (1)
- {
- }
- }
- #endif
- void fault_handler_c(unsigned int * hardfault_args, unsigned int type);
- ……………………
- …………限于本文篇幅 余下代碼請從51黑下載附件…………
復制代碼
所有資料51hei提供下載:
16字節(jié)加解密的AES算法.zip
(1.59 MB, 下載次數(shù): 400)
2018-4-26 15:18 上傳
點擊文件名下載附件
AES加密算法 下載積分: 黑幣 -5
|