Here you can find the source of secureTextDeletionFromTextField(JTextField textField, int length)
Parameter | Description |
---|---|
textField | the text field |
length | length of text in the text field |
public static void secureTextDeletionFromTextField(JTextField textField, int length)
//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); } }