Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid AES in C
    text
    copied!<p>I wanna encrypt my files on PC(Windows 7, 64bit) and decrypt 'em on Android.<br> <br> I use this algo to encrypt files.<br> <a href="http://gladman.plushost.co.uk/oldsite/AES/aes-byte-29-08-08.zip" rel="nofollow">http://gladman.plushost.co.uk/oldsite/AES/aes-byte-29-08-08.zip</a><br> <br> I encrypt my files on PC, push them to SDcard.<br> Unfortunately when I try to decrypt them on Android,<br> the result is different,<br> files are completely unreadable...!<br> <br> What's wrong with my code?<br></p> <pre><code>jbyteArray Java_com_example_hellojni_HelloJni_decrypt(JNIEnv* env, jobject thiz, jstring fileName) { ...... /* read the file into the buffer */ size_t result = fread (buffer_in, 1, file_size, fin); if (result!=file_size) { fputs("Reading error", stderr); exit(3); } /* end if */ fclose(fin); /* decrypt file */ aes_context ctx[1]; aes_set_key(key, 16, ctx); long i; for (i=0; i&lt;num_block; i++) { long begin = i*16; char *block = copyBlock(buffer_in, file_size, begin, 16), /* copy buffer_in[begin] ~ buffer_in[begin+16-1] to block[] */ *tmp = (char*)malloc(sizeof(char)*16); aes_decrypt(block, tmp, ctx); fillBuffer(buffer_out, out_size, tmp, begin, 16); /* copy tmp[] to buffer_out[begin] ~ buffer_out[begin+16-1] */ free(tmp); free(block); } /* end for */ ...... } /* end Java_com_example_hellojni_HelloJni_decrypt() */ </code></pre> <p>I know the discrepancy happens in aes.c:</p> <pre><code>return_type aes_set_key( const unsigned char key[], length_type keylen, aes_context ctx[1] ) { ...... for( cc = keylen, rc = 1; cc &lt; hi; cc += 4 ) { uint_8t tt, t0, t1, t2, t3; /* difference begins here */ t0 = ctx-&gt;ksch[cc - 4]; t1 = ctx-&gt;ksch[cc - 3]; t2 = ctx-&gt;ksch[cc - 2]; t3 = ctx-&gt;ksch[cc - 1]; ....... } /* end for */ return 0; } /* end aes_set_key() */ </code></pre> <p>but why?!<br> <br> Help needed badly!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload