酷代码 AI
菜单
服务商
DeepSeek字节豆包讯飞星火
更多选项

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]

相关提问
本站限时免费提问中
实用工具查看更多
Linux在线手册 [开发类]
Jquery在线手册 [开发类]
今日油价 [生活类]
图片互转base64 [开发类]
时间转换器 [开发类]