[問題] AES字串加解密(跨平台)
小弟利用AES作字串加解密,在windows和Linux測試成功
但是,跨平台卻無法正確解密,附上source code,麻煩各位大大給小弟一些可能的問題
Encrypt in Windows:
aes_context ctx;
char *rawData = "Hello world!";
char *secret_key = "SECRET_KEY";
unsigned char buf[16];
unsigned char key[32];
memset(buf,0,16);
memset(key,0,32);
memcpy( buf, rawData, 16);
/* Set the key */
memcpy( key, secret_key, 32);
aes_set_key( &ctx, key, 128);
/* Encrypt and save to file */
aes_encrypt( &ctx, buf, buf );
FILE *fp;
fp = fopen("SSL", "wb+");
fwrite(buf,1,16,fp);
fclose(fp);
Decrypt in Linux
aes_context ctx;
char *decryptData;
char *secret_key = "SECRET_KEY ";
unsigned char buf[16];
unsigned char key[32];
memset(buf,0,16);
memset(key,0,32);
/* Set the key */
memcpy( key, secret_key, 32);
aes_set_key( &ctx, key, 128);
/* Decrypt from file*/
FILE *fp;
fp = fopen("SSL", "rb+");
fread(buf, 1, 16, fp);
fclose(fp);
aes_decrypt( &ctx,buf,buf);
decryptData = (char*)buf;
cout<<decryptData<<endl;
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 210.200.169.82
推
05/15 14:10, , 1F
05/15 14:10, 1F
→
05/15 14:11, , 2F
05/15 14:11, 2F
推
05/15 14:13, , 3F
05/15 14:13, 3F
推
05/15 21:31, , 4F
05/15 21:31, 4F