/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.parelon.pskc;
import com.sun.org.apache.xml.internal.security.Init;
import com.sun.org.apache.xml.internal.security.utils.Base64;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.filechooser.FileNameExtensionFilter;
/**
* Tool to convert PSKC file involving RSA asymmetric encryption to PSKC file
* involving AES symmetric encryption.
*
* @author Vincenzo Abate
*/
public class MainWindow extends java.awt.Frame {
private byte[] fragment1, fragment2;
/**
* Creates new form MainWindow
*/
public MainWindow() {
Init.init();
initComponents();
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jFrame1 = new javax.swing.JFrame();
jFileChooser1 = new javax.swing.JFileChooser();
jPanel1 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
jPanel2 = new javax.swing.JPanel();
manufactuerTextField = new javax.swing.JTextField();
jLabel2 = new javax.swing.JLabel();
issuerTextField = new javax.swing.JTextField();
jLabel3 = new javax.swing.JLabel();
jPanel3 = new javax.swing.JPanel();
fileInTextField = new javax.swing.JTextField();
jLabel4 = new javax.swing.JLabel();
folderOutTextField = new javax.swing.JTextField();
jLabel5 = new javax.swing.JLabel();
browseFileIn = new javax.swing.JButton();
jLabel6 = new javax.swing.JLabel();
jPanel4 = new javax.swing.JPanel();
privateKeyFrammento1TextField = new javax.swing.JTextField();
jLabel7 = new javax.swing.JLabel();
privateKeyFrammento2TextField = new javax.swing.JTextField();
jLabel8 = new javax.swing.JLabel();
browsePrivateKeyFrammento1 = new javax.swing.JButton();
browsePrivateKeyFrammento2 = new javax.swing.JButton();
jLabel9 = new javax.swing.JLabel();
jLabel10 = new javax.swing.JLabel();
aesKeyTextField = new javax.swing.JTextField();
convertiButton = new javax.swing.JButton();
chiudiButton = new javax.swing.JButton();
jFileChooser1.setCurrentDirectory(null);
javax.swing.GroupLayout jFrame1Layout = new javax.swing.GroupLayout(jFrame1.getContentPane());
jFrame1.getContentPane().setLayout(jFrame1Layout);
jFrame1Layout.setHorizontalGroup(
jFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jFrame1Layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jFileChooser1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
jFrame1Layout.setVerticalGroup(
jFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jFrame1Layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jFileChooser1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
setBounds(new java.awt.Rectangle(0, 0, 500, 600));
setResizable(false);
setTitle("PSKC converter");
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
exitForm(evt);
}
});
jPanel1.setBackground(new java.awt.Color(255, 255, 255));
jLabel1.setFont(new java.awt.Font("Dialog", 1, 36)); // NOI18N
jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
jLabel1.setText("PSKC CONVERTER");
jLabel1.setFocusable(false);
jLabel1.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
jLabel1.setMaximumSize(new java.awt.Dimension(32767, 32767));
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 48, Short.MAX_VALUE)
.addContainerGap())
);
jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Device Info"));
manufactuerTextField.setText("Shenzen Seamoon Technology Co., Ltd.");
jLabel2.setText("Manufactuer");
issuerTextField.setText("Parlamento Elettronico Online");
jLabel3.setText("Issuer");
javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
.addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(manufactuerTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 441, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
.addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(issuerTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 441, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap())
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(manufactuerTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel2))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(issuerTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel3))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Seed Container"));
fileInTextField.setName("fileInTextField"); // NOI18N
jLabel4.setText("File IN");
jLabel5.setText("Folder OUT");
browseFileIn.setText("...");
browseFileIn.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
browseFileInMouseClicked(evt);
}
});
jLabel6.setFont(new java.awt.Font("Dialog", 0, 12)); // NOI18N
jLabel6.setText("Il \"File IN\" e' il file XML decriptato");
javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
jPanel3.setLayout(jPanel3Layout);
jPanel3Layout.setHorizontalGroup(
jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel3Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel3Layout.createSequentialGroup()
.addComponent(jLabel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
.addGroup(jPanel3Layout.createSequentialGroup()
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
.addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(fileInTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 331, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
.addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(folderOutTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 331, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(browseFileIn, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(62, 62, 62))))
);
jPanel3Layout.setVerticalGroup(
jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel6)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(browseFileIn, javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(fileInTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel4)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(folderOutTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel5))
.addContainerGap())
);
jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder("Chiavi"));
privateKeyFrammento1TextField.setName("fileInTextField"); // NOI18N
jLabel7.setText("Private Key Frammento 1");
jLabel8.setText("Private Key Frammento 2");
browsePrivateKeyFrammento1.setText("...");
browsePrivateKeyFrammento1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
browsePrivateKeyFrammento1MouseClicked(evt);
}
});
browsePrivateKeyFrammento2.setText("...");
browsePrivateKeyFrammento2.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
browsePrivateKeyFrammento2MouseClicked(evt);
}
});
jLabel9.setFont(new java.awt.Font("Dialog", 0, 12)); // NOI18N
jLabel9.setText("Chiave Privata di Criptazione");
jLabel10.setText("AES-128-CBC key");
aesKeyTextField.setEditable(false);
aesKeyTextField.setToolTipText("Chiave da inserire in LinOTP");
javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
jPanel4.setLayout(jPanel4Layout);
jPanel4Layout.setHorizontalGroup(
jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel4Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel4Layout.createSequentialGroup()
.addComponent(jLabel9, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
.addGroup(jPanel4Layout.createSequentialGroup()
.addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
.addComponent(jLabel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(privateKeyFrammento1TextField, javax.swing.GroupLayout.PREFERRED_SIZE, 331, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
.addComponent(jLabel8, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(privateKeyFrammento2TextField, javax.swing.GroupLayout.PREFERRED_SIZE, 331, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(browsePrivateKeyFrammento1, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(browsePrivateKeyFrammento2, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(62, 62, 62))
.addGroup(jPanel4Layout.createSequentialGroup()
.addComponent(jLabel10, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(aesKeyTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 331, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(122, 122, 122))))
);
jPanel4Layout.setVerticalGroup(
jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel9)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(browsePrivateKeyFrammento1, javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(privateKeyFrammento1TextField, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel7)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(privateKeyFrammento2TextField, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel8))
.addComponent(browsePrivateKeyFrammento2))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(aesKeyTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel10))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
convertiButton.setLabel("Converti");
convertiButton.setMaximumSize(new java.awt.Dimension(80, 20));
convertiButton.setMinimumSize(new java.awt.Dimension(80, 20));
convertiButton.setPreferredSize(new java.awt.Dimension(80, 20));
convertiButton.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
convertiButtonMouseClicked(evt);
}
});
chiudiButton.setLabel("Chiudi");
chiudiButton.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
chiudiButtonMouseClicked(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(convertiButton, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(100, 100, 100)
.addComponent(chiudiButton, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(140, 140, 140))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
.addComponent(convertiButton, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(chiudiButton, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
pack();
}// </editor-fold>//GEN-END:initComponents
/**
* Exit the Application
*/
private void exitForm(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_exitForm
System.exit(0);
}//GEN-LAST:event_exitForm
private void chiudiButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_chiudiButtonMouseClicked
System.exit(0);
}//GEN-LAST:event_chiudiButtonMouseClicked
private void convertiButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_convertiButtonMouseClicked
aesKeyTextField.setText("Inizializzazione");
new Thread(new Runnable() {
@Override
public void run() {
try {
if (privateKeyFrammento1TextField.getText().equals("") || privateKeyFrammento1TextField.getText().equals("")) {
throw new Exception("Seleziona tutte le chiavi prima.");
}
chiudiButton.setEnabled(false);
convertiButton.setEnabled(false);
browseFileIn.setEnabled(false);
//browseFolderOut.setEnabled(false);
browsePrivateKeyFrammento1.setEnabled(false);
browsePrivateKeyFrammento2.setEnabled(false);
XmlManager manager = new XmlManager(manufactuerTextField.getText(), issuerTextField.getText());
aesKeyTextField.setText("Generazione chiavi");
aesKeyTextField.setText(manager.initializeCrypto(fragment1, fragment2));
if (System.getProperty("os.name").startsWith("Windows")) {
manager.convertXml(folderOutTextField.getText() + "\\" + fileInTextField.getText(), folderOutTextField.getText() + "\\new_" + fileInTextField.getText());
} else {
manager.convertXml(folderOutTextField.getText() + "/" + fileInTextField.getText(), folderOutTextField.getText() + "/new_" + fileInTextField.getText());
}
JOptionPane.showMessageDialog(null, "XML convertito correttamente. Importare l'XML sul server di autenticazione inserendo la chiave AES indicata. NB: NON PERDERLO!");
fragment1 = null;
fragment2 = null;
} catch (Exception ex) {
JOptionPane.showMessageDialog(null, "Errore: " + ex.getMessage());
ex.printStackTrace();
}
chiudiButton.setEnabled(true);
convertiButton.setEnabled(true);
browseFileIn.setEnabled(true);
//browseFolderOut.setEnabled(true);
browsePrivateKeyFrammento1.setEnabled(true);
browsePrivateKeyFrammento2.setEnabled(true);
privateKeyFrammento1TextField.setText("");
privateKeyFrammento2TextField.setText("");
}
}).start();
}//GEN-LAST:event_convertiButtonMouseClicked
private void browsePrivateKeyFrammento1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_browsePrivateKeyFrammento1MouseClicked
try {
//this.jFileChooser1 = new JFileChooser();
this.jFileChooser1.setSelectedFile(null);
this.jFileChooser1.resetChoosableFileFilters();
FileNameExtensionFilter filter = new FileNameExtensionFilter("KEY fragment", "key");
this.jFileChooser1.setFileFilter(filter);
this.jFileChooser1.setVisible(true);
if (jFileChooser1.showOpenDialog(jLabel1) == JFileChooser.APPROVE_OPTION) {
this.privateKeyFrammento1TextField.setText(jFileChooser1.getSelectedFile().getCanonicalPath());
File f = new File(this.privateKeyFrammento1TextField.getText());
FileInputStream fis = new FileInputStream(f);
DataInputStream dis = new DataInputStream(fis);
byte[] temp = new byte[(int) f.length()];
dis.readFully(temp);
dis.close();
this.fragment1 = Base64.decode(temp);
}
} catch (Exception ex) {
JOptionPane.showMessageDialog(null, ex.getMessage());
ex.printStackTrace();
}
}//GEN-LAST:event_browsePrivateKeyFrammento1MouseClicked
private void browsePrivateKeyFrammento2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_browsePrivateKeyFrammento2MouseClicked
try {
this.jFileChooser1.setSelectedFile(null);
this.jFileChooser1.resetChoosableFileFilters();
FileNameExtensionFilter filter = new FileNameExtensionFilter("KEY fragment", "key");
this.jFileChooser1.setFileFilter(filter);
this.jFileChooser1.setVisible(true);
if (jFileChooser1.showOpenDialog(jLabel1) == JFileChooser.APPROVE_OPTION) {
this.privateKeyFrammento2TextField.setText(jFileChooser1.getSelectedFile().getCanonicalPath());
File f = new File(this.privateKeyFrammento2TextField.getText());
FileInputStream fis = new FileInputStream(f);
DataInputStream dis = new DataInputStream(fis);
byte[] temp = new byte[(int) f.length()];
dis.readFully(temp);
dis.close();
this.fragment2 = Base64.decode(temp);
}
} catch (Exception ex) {
JOptionPane.showMessageDialog(null, ex.getMessage());
ex.printStackTrace();
}
}//GEN-LAST:event_browsePrivateKeyFrammento2MouseClicked
private void browseFileInMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_browseFileInMouseClicked
try {
this.jFileChooser1.setSelectedFile(null);
this.jFileChooser1.resetChoosableFileFilters();
FileNameExtensionFilter filter = new FileNameExtensionFilter("PSKC file", "xml");
this.jFileChooser1.setFileFilter(filter);
this.jFileChooser1.setVisible(true);
if (jFileChooser1.showOpenDialog(jLabel1) == JFileChooser.APPROVE_OPTION) {
this.fileInTextField.setText(jFileChooser1.getSelectedFile().getAbsolutePath());
if (System.getProperty("os.name").startsWith("Windows")) {
this.fileInTextField.setText(jFileChooser1.getSelectedFile().getAbsolutePath().substring(jFileChooser1.getSelectedFile().getAbsolutePath().lastIndexOf("\\") + 1));
this.folderOutTextField.setText(jFileChooser1.getSelectedFile().getAbsolutePath().substring(0, jFileChooser1.getSelectedFile().getAbsolutePath().lastIndexOf("\\")));
} else {
this.fileInTextField.setText(jFileChooser1.getSelectedFile().getAbsolutePath().substring(jFileChooser1.getSelectedFile().getAbsolutePath().lastIndexOf("/") + 1));
this.folderOutTextField.setText(jFileChooser1.getSelectedFile().getAbsolutePath().substring(0, jFileChooser1.getSelectedFile().getAbsolutePath().lastIndexOf("/")));
}
}
} catch (Exception ex) {
JOptionPane.showMessageDialog(null, ex.getMessage());
ex.printStackTrace();
}
}//GEN-LAST:event_browseFileInMouseClicked
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new MainWindow().setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JTextField aesKeyTextField;
private javax.swing.JButton browseFileIn;
private javax.swing.JButton browsePrivateKeyFrammento1;
private javax.swing.JButton browsePrivateKeyFrammento2;
private javax.swing.JButton chiudiButton;
private javax.swing.JButton convertiButton;
private javax.swing.JTextField fileInTextField;
private javax.swing.JTextField folderOutTextField;
private javax.swing.JTextField issuerTextField;
private javax.swing.JFileChooser jFileChooser1;
private javax.swing.JFrame jFrame1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel10;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel7;
private javax.swing.JLabel jLabel8;
private javax.swing.JLabel jLabel9;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JPanel jPanel3;
private javax.swing.JPanel jPanel4;
private javax.swing.JTextField manufactuerTextField;
private javax.swing.JTextField privateKeyFrammento1TextField;
private javax.swing.JTextField privateKeyFrammento2TextField;
// End of variables declaration//GEN-END:variables
}