在C程序中,我试图用ECB模式加密AES 128
您好,在C程序中,我正在尝试在fedora操作系统上使用ECB模式加密AES 128 但我得到了分割错误(核心转储) 我向你提出请求,请帮助我。 提前感谢:-) 在运行程序之前 请保存在C程序中,我试图用ECB模式加密AES 128,c,encryption,cryptography,malloc,aes,C,Encryption,Cryptography,Malloc,Aes,您好,在C程序中,我正在尝试在fedora操作系统上使用ECB模式加密AES 128 但我得到了分割错误(核心转储) 我向你提出请求,请帮助我。 提前感谢:-) 在运行程序之前 请保存aes.h,aes.c,您可以在 你必须像这样运行程序 gcc main.c aes.c 数据是 {"RequestUniqueID":"987654321","MethodName":"DstGenerateSessionID"} 分段故障(堆芯转储) 我希望你能在代码中找到我的错 我的节目是 #includ
aes.h
,aes.c
,您可以在你必须像这样运行程序
gcc main.c aes.c
数据是
{"RequestUniqueID":"987654321","MethodName":"DstGenerateSessionID"}
分段故障(堆芯转储)
我希望你能在代码中找到我的错
我的节目是
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "aes.h"
#define min(a,b) (((a)<(b))?(a):(b))
unsigned char *aes128_func(unsigned char *in, unsigned char *aes_key, char type, unsigned int *len)
{
unsigned char ptext[KEY_128]={0},ctext[KEY_128]={0},*out=NULL;
unsigned char *temp_in=NULL,*temp_out=NULL;
aes_ctx_t *ctx = NULL;
if(!in || !len || !(aes_key && (strlen(aes_key) < 17))) return NULL;
init_aes();
if(!(ctx = aes_alloc_ctx(aes_key, KEY_128))) {
return NULL;
}
memset(ctx, 0, sizeof(*ctx));
*len = *len + ( (*len % 16) ? (16 - (*len % 16)): 0);
if(!(out =(char *)malloc(sizeof(*len+1))))
{
aes_free_ctx(ctx);
return NULL;
}
memset(out,0,*len+1);
temp_in=in;
temp_out=out;
do{
memset(ptext, 0, sizeof(ptext));
memset(ctext, 0, sizeof(ctext));
if(type==0){
memcpy(ptext, temp_in, min(sizeof(ptext),strlen(temp_in)));
aes_encrypt(ctx, ptext, ctext);
}else{
memcpy(ptext, temp_in, sizeof(ptext));
aes_decrypt(ctx, ptext, ctext);
}
memcpy(temp_out,ctext,KEY_128);
}while(((temp_in += KEY_128) < in+*len) && ((temp_out += KEY_128) < out+*len));
if(ctx) aes_free_ctx(ctx);
if(type==1) *len=strlen(out);
printf ("\nout aes %s\n",out);
return out;
}
unsigned char *process_post_data(unsigned char *in, unsigned char *aes_key, char type, unsigned int *ret_len)
{
unsigned char *step1_buf=NULL, *step2_buf=NULL;
unsigned int len=0;
printf ("at process_post_data \nin=%s\t aes_key=%s\t type=%s\t ret_len=%u\n", in, aes_key, type, ret_len);
if(!in || !aes_key) return NULL;
len = strlen(in);
if(type == 0)
{
if(!(step1_buf = aes128_func(in, aes_key, type, &len)))
return NULL;
printf ("\naes enc data is \"%s\" \n",step1_buf);
}
}
int main(int argc, char *argv[])
{
unsigned int ret_len;
char *data=NULL, *processed_data=NULL, *post_data=NULL;
data="{\"RequestUniqueID\":\"987654321\",\"MethodName\":\"DstGenerateSessionID\"}";
printf ("data is \t %s\n ",data);
if(!(processed_data = process_post_data(data,"1848519011345614",0,&ret_len)))
{
printf ("sorry something worng try again\n");
}
}
#包括
#包括
#包括
#包括“aes.h”
#定义min(a,b)((a)嗨,我终于解决了我的问题&感谢你试图帮助我:-)
我已将代码中的if(!(out=(char*)malloc(sizeof(*len+1)))更改为
要打印加密数据,我们必须在if(!(step1_buf=aes128_func(in,aes_key,type,&len))之后这样使用
printf(“a4 aes en数据为\n”);
对于(i=0;IAT程序中的哪个点做核心转储)?考虑设置单独的字段**CTX,而不是<代码> MSESET(CTX,0,SIZEOF(*CTX))< /C> >查看<代码> CTX-> KEXCHED 。“唯一请求�P�PS它正在打印垃圾数据。-chuxat if(ctx)aes_free_ctx(ctx);堆芯转储即将出现注意:这是基于德州仪器aes 128 C实现的aes 128位ECB最简单的C实现:
if(!(out =malloc(*len+1)))
printf ("a4 aes en data is \n");
for(i=0;i<strlen(step1_buf);i++)
printf ("%02x",step1_buf[i]);
printf ("\n");