내 프로그램에 대한 도움이 필요합니다. 아무도 이것으로 나를 도울 수 있습니까?잘못 입력 한 프로그램
감사합니다.
내 코드를 실행할 때마다, 내가받을 다음과 같은 출력 :
:
는하지만 출력이 많은 대신에 하나 개의 상자에 다음과 같이되고 싶어
코드 :
public class myDesCbc2 {
public static void main(String[] args) throws FileNotFoundException, UnsupportedEncodingException, IOException, NoSuchAlgorithmException, NoSuchPaddingException, InvalidAlgorithmParameterException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException {
JFrame frame = null;
JFileChooser fChoose = new JFileChooser(System.getProperty("user.home"));
int returnVal = fChoose.showOpenDialog(frame);
File myFile = fChoose.getSelectedFile();
//Read file and store to String line
FileInputStream fis = new FileInputStream(myFile);
BufferedReader stream = new BufferedReader(new InputStreamReader(fis, "ISO-8859-1"));
String file;
while ((file = stream.readLine()) != null) {
JOptionPane.showOptionDialog(
null, "Generating a 56-bit DES key...", "Processing...", JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, null, new Object[]{}, null);
// Create an 8-byte initialization vector
SecureRandom sr = new SecureRandom();
byte[] iv = new byte[8];
sr.nextBytes(iv);
IvParameterSpec IV = new IvParameterSpec(iv);
// Create a 56-bit DES key
KeyGenerator kg = KeyGenerator.getInstance("DES");
// Initialize with keysize
kg.init(56);
Key mykey = kg.generateKey();
JOptionPane.showOptionDialog(
null, "Your key has been generated!", "Processing...", JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, null, new Object[]{}, null);
// Create a cipher object and use the generated key to initialize it
Cipher cipher = Cipher.getInstance("DES/CBC/PKCS5Padding");
cipher.init(Cipher.ENCRYPT_MODE, mykey, IV);
byte[] plaintext = file.getBytes("UTF8");
// Encrypt the text
byte[] ciphertext = cipher.doFinal(plaintext);
JOptionPane.showMessageDialog(null,"\n\nCiphertext: ");
for (int i = 0; i < ciphertext.length; i++) {
if (chkEight(i)) {
System.out.print("\n");
}
JOptionPane.showMessageDialog(null,ciphertext[i] + " ");
}
}
}
}
chkEight 코드 :
public class chkEight {
public static Boolean chkEight (int num) {
int num1, rem;
num1 = num % 8;
if(num1== 0) {
return true;
}
else
{
return false;
}
}
}
그래, 프로그램은 종종 잘못된 출력을 제공합니다. 또는 적어도 당신이 "잘못"이라고 생각하는 것 - 사실상 모든 경우에 그들이하는 말을하는 것입니다. –