User Tools

Site Tools


This is an old revision of the document!

pysf - Transparent File Encryption in Python

A C library and Python wrapper allowing strong encryption of a file allowing for relatively random access patterns without having to decrypt the entire file in memory.


The file is locked with a passphrase and this is used to derive an encryption key via the PBKDF2 function. Files are split into fixed size blocks and each block is separately encrypted with a block cipher, where the IV is generated via a pseudo-random function for each block. Stream ciphers may be in appropriate as repeatedly encrypting different data with the same initial state can allow attacks to derive the key.

Splitting files into blocks allows more or less random access, as each block can be independently decrypted. The library can handle selection of blocks to load and decrypt, as well as any caching that might be required. The C API hides all aspects of this and allows two simple primitives to read and write a specific block of data from a specified offset within the file.

File Header

Byte Byte Byte Byte
0xAA 0x5F Version
Header length Cipher Mode
Key size Block size
Salt (encryption)
budget/pysf.1349527626.txt.gz · Last modified: 2012/10/12 08:32 (external edit)