AES字串加解密(跨平台) - Linux
By Ina
at 2013-05-15T12:40
at 2013-05-15T12:40
Table of Contents
小弟利用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;
--
但是,跨平台卻無法正確解密,附上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;
--
Tags:
Linux
All Comments
By Hedy
at 2013-05-20T03:46
at 2013-05-20T03:46
By Emily
at 2013-05-22T02:37
at 2013-05-22T02:37
By Andy
at 2013-05-24T13:58
at 2013-05-24T13:58
By Edith
at 2013-05-27T12:01
at 2013-05-27T12:01
Related Posts
debian桌面問題
By Faithe
at 2013-05-15T10:39
at 2013-05-15T10:39
FileZilla更新 3.6.0.2到3.7.0.1
By Dora
at 2013-05-14T22:31
at 2013-05-14T22:31
windows換到linux
By Frederica
at 2013-05-14T21:12
at 2013-05-14T21:12
HackingThursday 固定聚會 (2013-05-16)
By Elizabeth
at 2013-05-14T10:46
at 2013-05-14T10:46
自製 Ubuntu 與 Debian 測試硬體安裝使用的 USB 隨身碟
By Lauren
at 2013-05-13T16:23
at 2013-05-13T16:23