Alternatively, if you need it to get encrypted straight away and not once the dataobject is written, you could define setMyField(). This is the function that is called when you go $obj->MyField = 'value';