Encrypted pdf support - RadaeePDF.com - Results from #6
Signin/Signup with: 
Welcome, Guest
Username: Password: Remember me
Questions about Android development and PDF
  • Page:
  • 1
  • 2

TOPIC: Encrypted pdf support

Encrypted pdf support 3 years 11 months ago #9887

  • ruslan.iskhakov
  • ruslan.iskhakov's Avatar
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 9
  • Thank you received: 0
Thanks for the reply!

In other words, I would like to know what happens under the hood when the seek method of PDFAESStream is being called? When a new seek position less than the current encrypted file position is being passed, whether the encrypted file is closed first and reopened again? Or just 'seek backward' operation over the encrypted file is executed?

Please Log in or Create an account to join the conversation.

Encrypted pdf support 3 years 11 months ago #9897

  • radaee
  • radaee's Avatar
  • Offline
  • Moderator
  • Moderator
  • Posts: 917
  • Karma: 43
  • Thank you received: 19
OK, it is coding by me, other supports may not explan well.
PDFAESStream is block based encrypt/decrypt stream.
each origin block is 4080 bytes.
each encrypted block is 4096(4080 + 16) bytes, 16 bytes for CBC mode padding.

for encrypt file:
--split a file to blocks, each has 4080 bytes, last block may less than 4080.
--encrypt each block, and save 4096 bytes to another file.
for decrypt file:
--split encrypted file to blocks, each has 4096 bytes, last block may less that 4096, but must more than 16 bytes.
--decrypt each block, and save 4080 bytes to another file.

constant variables:
static private int BLOCK_ENC_SIZE = 4096;
static private int BLOCK_DEC_SIZE = BLOCK_ENC_SIZE-16;

for seek method implements::
1. check previous block need flush? if yes, write encrypted block back to file.
2. calcute block index by position: int block = pos / BLOCK_DEC_SIZE;
3. if block index of new position, is same to previous block index, return NOP.
4. otherwise, decode the new block, and release previous block.

all reading/writing from current position, is reading/writing on current block.
if position is out of byte range of current block, then flush current block, and reading/writing next block.

Please Log in or Create an account to join the conversation.

Last edit: by radaee.
  • Page:
  • 1
  • 2
Powered by Kunena Forum