Simple Crypt IO Device
Writing a Custom I/O Device with encryption via SimpleCrypt class
The example app can be found on gitorious: qtdevnet-wiki-mvc/qtdevnet-simplecryptiodevide [gitorious.org] .
The following code snippet shows how we would use the custom I/O device to encrypt data and store the result in a file:The
The basic implementation is the same as in Custom I/O Device. The big difference is, that the data can’t be stored directly when the client writes it to the device, as the encryption/decryption is done block wise.This means
EfficiencyNote that because
For reading, alway a complete block must be read from the device. Then the needed data is moved to the data buffer of the client. As there might be data left in the buffer, each read furst gets the data of the internal buffer. when it’s empty, new data is read from the underlying device.
The stored data always contains an int with the size of the encrypted buffer.
writeDataTo write the data to the underlying device, first the current block needs to be filled. To achieve this, all data is attached to the buffer
To ensure no data is left when the device is closed, during close or destructor, the last buffer is flushed to the device.