C语言实现SM4加解密:代码示例解析
#include <stdio.h> #include <string.h> #include "sm4.h" int main() { unsigned char key[16] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10}; unsigned char plaintext[16] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10}; unsigned char ciphertext[16]; unsigned char decrypttext[16]; // Encrypt sm4_context ctx; sm4_setkey_enc(&ctx, key); sm4_crypt_ecb(&ctx, 1, 16, plaintext, ciphertext); printf("Cipher Text:\n"); for(int i=0; i<16; i++) { printf("%02x", ciphertext[i]); } printf("\n"); // Decrypt sm4_setkey_dec(&ctx, key); sm4_crypt_ecb(&ctx, 0, 16, ciphertext, decrypttext); printf("Plain Text:\n"); for(int i=0; i<16; i++) { printf("%02x", decrypttext[i]); } printf("\n"); return 0; } ######[AI写代码神器 | 600点数解答 | 2024-11-08 09:28:02]
- Java实现链表反转:迭代与递归双解法详解及开发实战指南(DeepSeek | 1409点数解答 | 2026-03-15 15:09:29)60
- Python 实现球类:精准计算半径、表面积与体积,附输入验证与异常处理!(阿里通义 | 261点数解答 | 2024-11-28 21:19:39)382
- Golang开发:解析JSON数据时数值默认类型及示例解析(百度文心 | 393点数解答 | 2023-11-09 18:13:06)312
- SQL Working Areas Sizing: Manual vs. Automatic Policy - A Comprehensive Analysis(阿里通义 | 530点数解答 | 2024-05-13 10:55:58)331
- 探寻数组中最长摆动子序列长度:思路剖析与代码优化(GPT | 758点数解答 | 2024-12-23 23:18:29)290
- 独家剖析:求解数组最长摆动子序列长度的代码实现与改进建议(GPT | 350点数解答 | 2024-12-23 23:20:54)290
- Three.js 示例代码解析:优化场景渲染与注意要点(字节豆包 | 164点数解答 | 2025-02-27 23:30:20)287
- 51 单片机:定时器 0 实现 8 个 LED 循环点亮,附代码及优化建议(字节豆包 | 1193点数解答 | 2024-12-27 15:10:29)352
- 用 JS 中 for 循环实现 1 到 100 相加并输出结果到页面的完整代码 ( | 240点数解答 | 2024-05-20 22:11:29)500
- 用 JS 的 while 循环实现 1 到 100 相加并输出到页面的代码揭秘( | 47点数解答 | 2024-05-20 22:16:48)389
- C++实现读取数字并输出最小值的代码及解释(字节豆包 | 113点数解答 | 2026-03-20 19:32:56)30
- C语言:实现不超五位整数各位数值求和与输入验证( | 363点数解答 | 2024-03-09 14:33:57)285