Java JTextField secureTextDeletionFromTextField(JTextField textField, int length)

Here you can find the source of secureTextDeletionFromTextField(JTextField textField, int length)

Description

Deletes text from JTextField s in a secure way.

License

Open Source License

Parameter

Parameter Description
textField the text field
length length of text in the text field

Declaration

public static void secureTextDeletionFromTextField(JTextField textField, int length) 

Method Source Code

//package com.java2s;
/******************************************************************************
 * Copyright (c) 2008 Stefan Franke                                           *
 *                                                                            *
 * This file is part of OpenVPN SysTray.                                      *
 *                                                                            *
 * OpenVPN SysTray is free software: you can redistribute it and/or modify    *
 * it under the terms of the GNU General Public License as published by       *
 * the Free Software Foundation, version 2 of the License.                    *
 *                                                                            *
 * OpenVPN SysTray is distributed in the hope that it will be useful,         *
 * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              *
 * GNU General Public License for more details.                               *
 *                                                                            *
 * You should have received a copy of the GNU General Public License          *
 * along with OpenVPN SysTray.  If not, see <http://www.gnu.org/licenses/>.   *
 ******************************************************************************/

import javax.swing.JTextField;
import sun.security.provider.SecureRandom;

public class Main {
    /**/*from   w ww  . j av a2  s . co  m*/
     * The empty string
     */
    private static final String EMPTY_STRING = "";

    /**
     * Deletes text from {@link JTextField}s in a secure way.
     *
     * @param textField the text field
     * @param length length of text in the text field
     */
    public static void secureTextDeletionFromTextField(JTextField textField, int length) {
        byte[] bytes = new byte[length];
        new SecureRandom().engineNextBytes(bytes);
        String str = new String(bytes, 0, length);
        textField.setText(str);
        textField.setText(EMPTY_STRING);
    }
}

Related

  1. onTextFieldChange(JTextField field, final Runnable task)
  2. parseTextFieldInteger(JTextField field)
  3. ponerMayuscula(KeyEvent e, JTextField textField)
  4. quickButtonFlip(JTextField t, JTextField a, JTextField b)
  5. readBufferedImage(JTextField out)
  6. setEnabled(JTextField textField, boolean b)
  7. setEnabled(JTextField textField, boolean enabled)
  8. setModelValue(JTextField tf, String value)
  9. setText(JTextField jField, Object pObject, Object pDefault)