Upon occurrence of a trigger condition, writes of allocation units of data
(including code) to a device, such as writes of blocks to a disk, are
first encrypted. Each allocation unit is preferably a predetermined
integral multiple number of minimum I/O units. A data structure is marked
to indicate which units are encrypted. Upon reads from the device, only
those allocation units marked as encrypted are decrypted. The disk
protected by selective encryption is preferably the virtual disk of a
virtual machine (VM). The trigger condition is preferably either that the
virtual disk has been initialized or that the VM has been powered on.
Mechanisms are also provided for selectively declassifying (storing in
unencrypted form) already-encrypted, stored data, and for determining
which data units represent public, general-use data units that do not
need to be encrypted. The "encrypt-on-write" feature of the invention may
be used in conjunction with a "copy-on-write" technique.