public void writeObject ( ObjectOutputStream out ) throws IOException { out . defaultWriteObject ( ) ; ByteArrayOutputStream byteOut = new ByteArrayOutputStream ( ) ; ObjectOutputStream oOut = new ObjectOutputStream ( byteOut ) ; oOut . writeObject ( _clearCreds ) ; try { byte [ ] encrypted = SecureUtil . getAESCipher ( Cipher . ENCRYPT_MODE , _key ) . doFinal ( byteOut . toByteArray ( ) ) ; out . writeInt ( encrypted . length ) ; out . write ( encrypted ) ; } catch ( GeneralSecurityException gse ) { IOException ioe = new IOException ( "Failed to encrypt credentials" ) ; ioe . initCause ( gse ) ; throw ioe ; } }
A customized AES encrypting write object .