How to make an expanding compressed encrypted disk image?

Solution 1:

This is exactly what a dmg does.

To create one use Disk Utility and hit the New Image icon. Then choose the size, encryption and choose the image format as one of the sparse images. Even if you choose a large size it will only take up space according to what you save in it.

Solution 2:

You can not write to a disk image where the format is compressed

… files in and out …

The compressed formats do not allow addition, edition or removal.

You can use existing files to create an image with a compressed format. Write once.

If you create a new blank disk image that is compressed — with or without encryption — it will be relatively useless:

New blank image dialogue, image format: sparse bundle disk image

image format: compressed (write-once)

Compressed — write once. The one write occurs when you create the image — not afterwards. The resulting volume is read only:

the resulting volume is read only

You can use Disk Utility to convert a compressed image to a format that allows writing. At http://www.wuala.com/%23%23Apple-support/members/grahamperrin/2011/08/04/a/?mode=gallery I posted a five-minute movie showing two conversions.