How to make an expanding compressed encrypted disk image?
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.