1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
class ImportListener implements ActionListener{
public void actionPerformed(ActionEvent e){
Object source = e.getSource();
JFileChooser chooser = new JFileChooser(".");
YFileFilter filtre = new YFileFilter(".rsay", "Fichier RSA Crypt");
chooser.addChoosableFileFilter(filtre);
File file;
if(chooser.showOpenDialog(null) ==JFileChooser.APPROVE_OPTION){
file = chooser.getSelectedFile();
if(chooser.getFileFilter().accept(file))
{
try {
DataInputStream dis = new DataInputStream(new BufferedInputStream(new FileInputStream(file)));
int i = 0;
int n = 0;
byte b;
while((i = dis.read()) != -1){
n++;
}
byte[] buf = new byte[n];
//System.out.println("n = "+n);
DataInputStream dis2 = new DataInputStream(new BufferedInputStream(new FileInputStream(file)));
//while((b = dis2.readByte()) != -1){
for(int j = 0; j < n; j++){
buf[j] = dis2.readByte();
//System.out.println("byte n°"+j+" = "+buf[j]);
}
dis.close();
dis2.close();
if(source == publickey){
keyPublic = buf;
System.out.println(new BigInteger(keyPublic).toString());
}else{
//keyPrivate = str.getBytes();
}
} catch (FileNotFoundException e1) {
e1.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
}
}
else{
JOptionPane alert = new JOptionPane();
alert.showMessageDialog(null, "Erreur d'extension de fichier ! \nVotre chargement a échoué !", "Erreur", JOptionPane.ERROR_MESSAGE);
}
}
}
} // Fin de la class ImportListener |
Partager