I want to encrypt my files on a PC (Windows 7, 64 bit) and decrypt them on Android.
I use this algorithm to encrypt files.
http://gladman.plushost.co.uk/oldsite/AES/aes-byte-29-08-08.zip
I encrypt my files on the PC, click them on the SD card.
Unfortunately, when I try to decrypt them on Android, the
result is different, the
files are not completely readable ...!
What is wrong with my code?
jbyteArray Java_com_example_hellojni_HelloJni_decrypt(JNIEnv* env, jobject thiz, jstring fileName) {
......
size_t result = fread (buffer_in, 1, file_size, fin);
if (result!=file_size) { fputs("Reading error", stderr); exit(3); }
fclose(fin);
aes_context ctx[1];
aes_set_key(key, 16, ctx);
long i;
for (i=0; i<num_block; i++) {
long begin = i*16;
char *block = copyBlock(buffer_in, file_size, begin, 16),
*tmp = (char*)malloc(sizeof(char)*16);
aes_decrypt(block, tmp, ctx);
fillBuffer(buffer_out, out_size, tmp, begin, 16);
free(tmp);
free(block);
}
......
}
I know that the discrepancy occurs in aes.c:
return_type aes_set_key( const unsigned char key[], length_type keylen, aes_context ctx[1] ) {
......
for( cc = keylen, rc = 1; cc < hi; cc += 4 ) {
uint_8t tt, t0, t1, t2, t3;
t0 = ctx->ksch[cc - 4];
t1 = ctx->ksch[cc - 3];
t2 = ctx->ksch[cc - 2];
t3 = ctx->ksch[cc - 1];
.......
}
return 0;
}
but why?!
Help is bad!
source
share