Simultaneous Read/Write Android Encryption additional bytes & repitition -


I'm currently trying to encrypt the same file simultaneously (for security reasons) to securley, then cipher reading. I have received almost the code written below but adds extra bytes to the decrypted file. The decrypt method is almost in addition to c.init DECRYPT_MODE. Public static void encryptFile (string path, byte [] key) throws exception {cipher c = Cipher.getInstance ("AES / ECB / PKCS5Padding"); SPEAKEK of Secrets = New Secret of CPC (Key, "AES"); C.init (cipher NCRVPTMODE, K); RandomAccessFile RF = New RandomAccessFile (Path, "RW"); Byte [] buf = new byte [256]; Byte [] output; Int BitesRad = 0; Int total; tes = 0; While ((Bytes read = RF.Red (buff))> = 0) {int len ​​= buf.length; If (bytesRead & lt; lane) {byte [] out2 = c.doFinal (buf, 0, bytesRead); Raf.seek (totalBytes); Raf.write (out2); } Other {output = c. Update (buff, 0, bytes read); Raf.seek (totalBytes); Raf.write (production); } TotalBytes + = Bytes Reid; } Raf.getFD () Sync (); Raf.close (); }

Decrypted Example

Some graduates are going to double their original student loan twice in the new fee system in England May suggest math statistics for the BBC.

Statistics, by the main accountant, show that a student lends a £ 39,000 to a three-year course ?? A] is a £ ^ * z§Dþà ?? One ?? ùN \ a ?? A] a £ ^ * z§Dþà ?? One ?? ùNree year-old course of ree year-old course can pay back up to £ 83,000 in total, in cash conditions.

Due to the rule, starting in 2012, the graduates will make 9% of their earnings back for 30 years.

The government says that the system is fair and wished to charge up to £ 9,000 per year, which will be exposed by the government, from 2012, but after earning the student 21,000 pounds or more, the payment Will do

This debug and functions like I expected, I'm still confused as to how these bytes / repetition is getting here (possibly padding or wrong doodle) any suggestions Would be greatly appreciated:] Thanks!

It seemed that I did not believe that the last 16 bytes of each update Attaching to the next call. By adding 16 bytes to RF.Sec, we remain consistent with the data and add dotfenal correctly. Also use output.length to find the correct parameter to the file pointer. In the output of MD5s are accurate and the output seems to work! :] The decrypt function uses raf.setLength (totalBytes + output.length); Public static zero encrypt file (string path, byte [] key throws an exception {cipher c = Cipher.getInstance ("AES / ECB / PKCS5Padding"); SPEAKEK of Secrets = New Secret of CPC (Key, "AES"); C.init (cipher NCRVPTMODE, K); RandomAccessFile RF = New RandomAccessFile (Path, "RW"); Byte [] buf = new byte [128]; Int BitesRad = 0; Int total; tes = 0; Byte [] output; While ((bytes read = RF.rade (buff))> gt; = 0) {output = c. Update (buff, 0, bytes read); Raf.seek (totalBytes); Raf.write (production); Total + = Output. Length; Raf.seek (totalBytes + 16); } Output = c.doFinal (); Raf.seek (totalBytes); Raf.write (production); Raf.getFD () sync () .; Raf.close (); }

Comments