久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 13223|回復: 22
打印 上一主題 下一主題
收起左側

STM32 16字節(jié)加解密的AES算法程序源碼

  [復制鏈接]
跳轉到指定樓層
樓主
ID:82014 發(fā)表于 2018-4-26 15:19 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
stm32 AES動態(tài)加密算法,大家可以下載進行測試

1、該算法工程是基于Keil5環(huán)境進行編譯下載,單片機型號是stm32f030c8.

2、打開文件夾Project,雙擊"16BytesAES.uvprojx",即可打開工程。

3、如果不想利用該工程,只需要拷貝文件夾USER下的AES.c,AES.h,main.c到自己的工程,修改頭文件即可。

stm32單片機源程序如下:
  1. /**
  2.   ******************************************************************************
  3.   * @file    GPIO/GPIO_IOToggle/main.c
  4.   * @author  MCD Application Team
  5.   * @version V1.4.0
  6.   * @brief   Main program body
  7.   ******************************************************************************
  8.   * @attention
  9.   *
  10.   * <h2><center>© COPYRIGHT 2014 STMicroelectronics</center></h2>
  11.   *
  12.   * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
  13.   * You may not use this file except in compliance with the License.
  14.   * You may obtain a copy of the License at:
  15.   *
  16.   *        http://www.st.com/software_license_agreement_liberty_v2
  17.   *
  18.   * Unless required by applicable law or agreed to in writing, software
  19.   * distributed under the License is distributed on an "AS IS" BASIS,
  20.   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  21.   * See the License for the specific language governing permissions and
  22.   * limitations under the License.
  23.   *
  24.   ******************************************************************************
  25.   */

  26. /* Includes ------------------------------------------------------------------*/
  27. #include "stm32f0xx.h"
  28. #include "stm32f0xx_conf.h"
  29. #include "stdio.h"
  30. #include "stdlib.h"
  31. #include "Mcu_config.h"
  32. #include "Serial.h"
  33. #include "AES.h"

  34. /** @addtogroup STM32F0xx_StdPeriph_Examples
  35.   * @{
  36.   */

  37. /** @addtogroup GPIO_IOToggle
  38.   * @{
  39.   */

  40. /* Private typedef -----------------------------------------------------------*/
  41. /* Private define ------------------------------------------------------------*/

  42. #ifdef __GNUC__
  43.   /* With GCC/RAISONANCE, small printf (option LD Linker->Libraries->Small printf
  44.      set to 'Yes') calls __io_putchar() */
  45.   #define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
  46. #else
  47.   #define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
  48. #endif /* __GNUC__ */
  49.        
  50.        
  51.        

  52. /* Private macro -------------------------------------------------------------*/
  53. /* Private variables ---------------------------------------------------------*/


  54. /* Private function prototypes -----------------------------------------------*/
  55. /* Private functions ---------------------------------------------------------*/

  56. /**
  57.   * @brief  Main program.
  58.   * @param  None
  59.   * @retval None
  60.   */


  61. char expressText[1024];  //存放待加密的明文數(shù)據(jù),具體緩存大小根據(jù)用戶待加密數(shù)據(jù)長度自己任意修改
  62. char cipherText[1024];//存放已加密的密文數(shù)據(jù),具體緩存大小根據(jù)用戶解密后的數(shù)據(jù)長度自己任意修改
  63. char aesKey[16];//加解密的密鑰,注意:此算法只適用于AES16位密鑰加解密,不適用于32位密鑰加解密

  64. //該AES算法加密方式為:AES-128bit/ECB/PKCS5Padding

  65. /*
  66. 歡迎加入
  67. 二手開發(fā)板供求交易群  68936520
  68. arm交流學習群    324753668
  69. stm32交流學習群  227043677
  70. */
  71. int main(void)
  72. {
  73.         MCU_Init();
  74.        
  75.         delay_1ms(2000);
  76.        
  77.         memcpy(aesKey , "1uweiIDAS7awOas8" , 16);  //AES加密密鑰,16字節(jié)(128bit)
  78.        
  79.         memset(expressText ,0 ,1024);
  80.         memset(cipherText , 0 ,1024);
  81.         strcpy(expressText , "Hello!!!Are you ready???");
  82.         AES_Encrypt(expressText  , cipherText , aesKey);        //use aesKey encrypt
  83.        
  84.         memset(expressText ,0 ,1024);
  85.         AES_Decrypt(expressText , cipherText , aesKey);//use aesKey decrypt               

  86.   while(1)
  87.   {

  88.                 delay_1ms(2000);
  89.   }
  90.        
  91. }

  92. /**
  93.   * @brief  Retargets the C library printf function to the USART.
  94.   * @param  None
  95.   * @retval None
  96.   */
  97. PUTCHAR_PROTOTYPE
  98. {
  99.   /* Place your implementation of fputc here */
  100.   /* e.g. write a character to the USART */
  101.        
  102.   USART_SendData(USART2, (uint8_t) ch);

  103.   /* Loop until transmit data register is empty */
  104.   while (USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET)
  105.   {}

  106.   return ch;
  107. }
  108. #ifdef  USE_FULL_ASSERT

  109. /**
  110.   * @brief  Reports the name of the source file and the source line number
  111.   *         where the assert_param error has occurred.
  112.   * @param  file: pointer to the source file name
  113.   * @param  line: assert_param error line source number
  114.   * @retval None
  115.   */
  116. void assert_failed(uint8_t* file, uint32_t line)
  117. {
  118.   /* User can add his own implementation to report the file name and line number,
  119.      ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */

  120.   /* Infinite loop */
  121.   while (1)
  122.   {
  123.   }
  124. }
  125. #endif

  126. void fault_handler_c(unsigned int * hardfault_args, unsigned int type);
  127. ……………………

  128. …………限于本文篇幅 余下代碼請從51黑下載附件…………
復制代碼

所有資料51hei提供下載:

16字節(jié)加解密的AES算法.zip (1.59 MB, 下載次數(shù): 400)


分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏8 分享淘帖 頂2 踩
回復

使用道具 舉報

沙發(fā)
ID:318517 發(fā)表于 2018-4-28 16:20 | 只看該作者
好資料,學習下
回復

使用道具 舉報

板凳
ID:318517 發(fā)表于 2018-5-2 15:20 | 只看該作者
學習
回復

使用道具 舉報

地板
ID:355846 發(fā)表于 2018-6-21 11:00 | 只看該作者
很好,下來學習一下。
回復

使用道具 舉報

5#
ID:164590 發(fā)表于 2018-8-28 09:49 | 只看該作者
好好學習一下!
回復

使用道具 舉報

6#
ID:349170 發(fā)表于 2018-8-31 15:38 | 只看該作者
加密模式是什么?ECB,CBC,CTR?
回復

使用道具 舉報

7#
ID:90358 發(fā)表于 2018-9-3 14:44 | 只看該作者
測試沒通過
回復

使用道具 舉報

8#
ID:106325 發(fā)表于 2019-1-23 14:52 | 只看該作者
好資料不錯
回復

使用道具 舉報

9#
ID:289330 發(fā)表于 2019-1-23 16:13 | 只看該作者
好資料,不錯
回復

使用道具 舉報

10#
ID:152003 發(fā)表于 2019-1-24 10:16 | 只看該作者
好資料 試一下
回復

使用道具 舉報

11#
ID:393586 發(fā)表于 2019-3-7 10:56 | 只看該作者
代碼有問題,測試結果錯誤
回復

使用道具 舉報

12#
ID:553992 發(fā)表于 2019-6-4 11:51 | 只看該作者




//去除末尾補碼
        buIndex = str2[aesDataLen-1];
        for(i=0; i<buIndex; i++)
        {
                if(str2[aesDataLen-i-1] != buIndex)
                {
                        //UART_Printf("\nit is a wrong data. \n");
                       
            //free(str2);   //pming,2019.06.04
                        //return;
            break;
                }
                else
                        str2[aesDataLen-i-1] = '\0';
        
        }
        strcpy(pExpressText , str2);
        free(str2);

解密返回為空。我將 加日期批注的地方2行,修改之后,可以解密。但長度似乎不對。
回復

使用道具 舉報

13#
ID:256220 發(fā)表于 2019-7-4 19:34 | 只看該作者
樓主的東西我測試了的,ok,沒問題,謝謝
回復

使用道具 舉報

14#
ID:475809 發(fā)表于 2019-8-26 09:46 | 只看該作者
下載幾次都失敗了
回復

使用道具 舉報

15#
ID:195932 發(fā)表于 2019-8-29 04:39 | 只看該作者
好資料,學習下
回復

使用道具 舉報

16#
ID:245560 發(fā)表于 2019-9-5 16:02 | 只看該作者
遇到了12樓一樣的問題,解密后返回為空
回復

使用道具 舉報

17#
ID:491881 發(fā)表于 2019-9-20 15:11 | 只看該作者
好資料,學習下
回復

使用道具 舉報

18#
ID:642434 發(fā)表于 2019-11-15 09:45 | 只看該作者
看起來資料不錯, 沒分下載, 樓主能不能分少點
回復

使用道具 舉報

19#
ID:407413 發(fā)表于 2019-12-6 17:20 | 只看該作者
解密數(shù)據(jù)為空的啊
回復

使用道具 舉報

20#
ID:147591 發(fā)表于 2019-12-9 10:20 | 只看該作者
試試看能不能用
回復

使用道具 舉報

21#
ID:635961 發(fā)表于 2020-2-24 11:20 | 只看該作者
謝謝分享,剛好想?yún)⒖家幌拢瑢W習AES加密
回復

使用道具 舉報

22#
ID:594820 發(fā)表于 2020-4-2 22:18 | 只看該作者
正好用到,謝謝分享!
回復

使用道具 舉報

23#
ID:800529 發(fā)表于 2023-12-14 10:12 | 只看該作者
我現(xiàn)在也需要,下載學習。
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網(wǎng)

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 国产精品视频一区二区三区 | 精品久久久久久亚洲精品 | 天天干天天操天天爽 | 日本精品裸体写真集在线观看 | 亚洲视频免费在线看 | 久久久久国产一区二区三区不卡 | 91av在线不卡 | 日韩在线一区二区三区 | 毛片a级毛片免费播放100 | 欧美一区二区三区高清视频 | 密桃av| 欧美一级电影免费 | 99久久婷婷国产综合精品电影 | 国产精品久久久久一区二区三区 | 国产一区二区三区在线视频 | 刘亦菲国产毛片bd | av播播| 久草资源| 日韩视频一区二区三区 | 国精产品一品二品国精在线观看 | 在线国产一区 | 国产亚洲精品久久久久久牛牛 | 久久精品国产99国产精品亚洲 | 岛国午夜 | 激情久久网 | 91成人免费 | 中文字幕日本一区二区 | 国产伦精品一区二区三区四区视频 | 日本精品一区二区三区在线观看视频 | 欧美成人免费在线 | av在线天堂网 | 欧美一区二区三区在线免费观看 | 在线欧美 | 国产激情视频在线 | 一区二区三区小视频 | 久久免费国产 | 亚洲第一区久久 | 暖暖日本在线视频 | 91视频大全 | 很很干很很日 | 一区二区精品视频 |