private void restore ( ) { Preferences pref = Preferences . userNodeForPackage ( ConnectionDialog . class ) ; getHostField ( ) . setText ( pref . get ( "host" , "localhost" ) ) ; getUserField ( ) . setText ( pref . get ( "user" , "guest" ) ) ; boolean remember = pref . getBoolean ( "remember" , false ) ; boolean passwordSet = false ; getRememberPasswordCheckBox ( ) . setSelected ( remember ) ; if ( remember ) { byte [ ] cipherText = pref . getByteArray ( "password" , null ) ; if ( cipherText != null ) { try { Cipher cipher = Cipher . getInstance ( "AES/CBC/PKCS5Padding" ) ; KeyGenerator keygen = KeyGenerator . getInstance ( "AES" ) ; SecureRandom random = SecureRandom . getInstance ( "SHA1PRNG" ) ; random . setSeed ( new byte [ ] { 0x60 , ( byte ) 0xFD , 0x28 , 0x07 , 0x35 , 0x4A , 0x0D , 0x3B } ) ; byte [ ] iv = new byte [ 16 ] ; random . nextBytes ( iv ) ; IvParameterSpec spec = new IvParameterSpec ( iv ) ; keygen . init ( 128 , random ) ; cipher . init ( Cipher . DECRYPT_MODE , keygen . generateKey ( ) , spec ) ; byte [ ] clearText = cipher . doFinal ( cipherText ) ; String password = new String ( clearText ) ; getPasswordField ( ) . setText ( password ) ; passwordSet = true ; } catch ( Exception e ) { logger . error ( "Could not decrypt password" , e ) ; } } } if ( ! passwordSet ) { getPasswordField ( ) . setText ( "" ) ; } }
Restores persisted field values from preferences .