gui.InboxPanel.java Source code

Java tutorial

Introduction

Here is the source code for gui.InboxPanel.java

Source

/*
 * 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 gui;

import blockcipher.BlockCipher;
import blockcipher.StringByteModifier;
import com.google.api.client.repackaged.org.apache.commons.codec.binary.Base64;
import com.google.api.services.gmail.model.Message;
import java.awt.Component;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javamailclient.GmailAPI;
import javax.mail.MessagingException;
import javax.swing.DefaultListCellRenderer;
import javax.swing.JFileChooser;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.ListSelectionModel;
import javax.swing.filechooser.FileNameExtensionFilter;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import signature.BigPoint;
import signature.ECDSA;

/**
 *
 * @author user
 */
public class InboxPanel extends javax.swing.JPanel {

    byte[] key;
    byte[] cipher;
    byte[] plain;
    String message;
    BigPoint publickey;
    String curId;

    /**
     * Creates new form InboxPanel
     */
    public InboxPanel() {
        initComponents();
    }

    public void generate() {
        Message[] arrMsg = GmailAPI.Inbox.toArray(new Message[GmailAPI.Inbox.size()]);
        InboxList = new JList(arrMsg);
        InboxList.setCellRenderer(new DefaultListCellRenderer() { // Setting the DefaultListCellRenderer
            public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
                    boolean cellHasFocus) {
                Message message = (Message) value; // Using value we are getting the object in JList
                Map<String, String> map = null;
                try {
                    map = GmailAPI.getMessageDetails(message.getId());
                } catch (MessagingException ex) {
                    Logger.getLogger(InboxPanel.class.getName()).log(Level.SEVERE, null, ex);
                } catch (IOException ex) {
                    Logger.getLogger(InboxPanel.class.getName()).log(Level.SEVERE, null, ex);
                }
                String sub = map.get("subject");
                if (map.get("subject").length() > 22) {
                    sub = map.get("subject").substring(0, 20) + "...";
                }
                setText(sub); // Setting the text
                //setIcon( shape.getImage() ); // Setting the Image Icon
                return this;
            }
        });
        InboxList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        InboxList.setLayoutOrientation(JList.VERTICAL);
        InboxList.setVisibleRowCount(-1);
        jScrollPane1.setViewportView(InboxList);

        InboxList.addMouseListener(new MouseAdapter() {
            public void mouseClicked(MouseEvent evt) {
                try {
                    JList list = (JList) evt.getSource();
                    int index = list.locationToIndex(evt.getPoint());
                    String id = arrMsg[index].getId();
                    curId = id;
                    Map<String, String> map = GmailAPI.getMessageDetails(id);
                    jTextField1.setText(map.get("from"));
                    jTextField2.setText(map.get("subject"));
                    dateTextField.setText(map.get("senddate"));
                    BodyTextPane.setText(map.get("body"));
                    //BodyTextPane.setContentType("text/html");
                    //BodyTextArea.setCo
                } catch (IOException ex) {
                    Logger.getLogger(InboxPanel.class.getName()).log(Level.SEVERE, null, ex);
                } catch (MessagingException ex) {
                    Logger.getLogger(InboxPanel.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        });
    }

    /**
     * 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.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        InboxList = new javax.swing.JList();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jTextField2 = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        decryptCheckBox = new javax.swing.JCheckBox();
        keyDecryptLabel = new javax.swing.JLabel();
        keyDecryptTextField = new javax.swing.JTextField();
        decryptFromFileCheckBox = new javax.swing.JCheckBox();
        openDecryptButton = new javax.swing.JButton();
        verifyCheckBox = new javax.swing.JCheckBox();
        verifyLabel = new javax.swing.JLabel();
        verifyTextField = new javax.swing.JTextField();
        verifyFromFileCheckBox = new javax.swing.JCheckBox();
        openVerifyButton = new javax.swing.JButton();
        decyptButton = new javax.swing.JButton();
        verifyButton = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        dateTextField = new javax.swing.JTextField();
        jButton3 = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        BodyTextPane = new javax.swing.JTextArea();

        InboxList.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };

            public int getSize() {
                return strings.length;
            }

            public Object getElementAt(int i) {
                return strings[i];
            }
        });
        jScrollPane1.setViewportView(InboxList);

        jLabel1.setText("From");

        jLabel2.setText("Subject");

        jTextField1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField1ActionPerformed(evt);
            }
        });

        jButton1.setText("<<");

        jButton2.setText(">>");

        decryptCheckBox.setText("Decrypt");
        decryptCheckBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                decryptCheckBoxActionPerformed(evt);
            }
        });

        keyDecryptLabel.setText("Key");
        keyDecryptLabel.setEnabled(false);

        keyDecryptTextField.setEnabled(false);

        decryptFromFileCheckBox.setText("File");
        decryptFromFileCheckBox.setEnabled(false);
        decryptFromFileCheckBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                decryptFromFileCheckBoxActionPerformed(evt);
            }
        });

        openDecryptButton.setText("Open");
        openDecryptButton.setEnabled(false);
        openDecryptButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                openDecryptButtonActionPerformed(evt);
            }
        });

        verifyCheckBox.setText("Verify");
        verifyCheckBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                verifyCheckBoxActionPerformed(evt);
            }
        });

        verifyLabel.setText("Key");
        verifyLabel.setEnabled(false);

        verifyTextField.setEnabled(false);

        verifyFromFileCheckBox.setText("File");
        verifyFromFileCheckBox.setEnabled(false);
        verifyFromFileCheckBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                verifyFromFileCheckBoxActionPerformed(evt);
            }
        });

        openVerifyButton.setText("Open");
        openVerifyButton.setEnabled(false);
        openVerifyButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                openVerifyButtonActionPerformed(evt);
            }
        });

        decyptButton.setText("Decrypt");
        decyptButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                decyptButtonActionPerformed(evt);
            }
        });

        verifyButton.setText("Verify");
        verifyButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                verifyButtonActionPerformed(evt);
            }
        });

        jLabel3.setText("Date");

        jButton3.setText("View Attachment");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        BodyTextPane.setColumns(20);
        BodyTextPane.setRows(5);
        jScrollPane2.setViewportView(BodyTextPane);

        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)
                                .addGroup(layout.createSequentialGroup().addComponent(jButton1)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(jButton2))
                                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 134,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(layout.createSequentialGroup().addGroup(layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addGroup(layout.createSequentialGroup().addGroup(layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(jLabel2).addComponent(jLabel1)).addGap(18, 18, 18)
                                                .addGroup(layout
                                                        .createParallelGroup(
                                                                javax.swing.GroupLayout.Alignment.LEADING, false)
                                                        .addComponent(jTextField2,
                                                                javax.swing.GroupLayout.DEFAULT_SIZE, 320,
                                                                Short.MAX_VALUE)
                                                        .addComponent(jTextField1)))
                                        .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 374,
                                                Short.MAX_VALUE))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addGroup(layout.createSequentialGroup().addGroup(layout
                                                        .createParallelGroup(
                                                                javax.swing.GroupLayout.Alignment.TRAILING, false)
                                                        .addComponent(keyDecryptTextField,
                                                                javax.swing.GroupLayout.Alignment.LEADING)
                                                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout
                                                                .createSequentialGroup()
                                                                .addComponent(verifyFromFileCheckBox)
                                                                .addPreferredGap(
                                                                        javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                                                        31, Short.MAX_VALUE)
                                                                .addComponent(openVerifyButton))
                                                        .addComponent(verifyButton,
                                                                javax.swing.GroupLayout.Alignment.LEADING,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE, 71,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                                        .addComponent(decryptCheckBox,
                                                                javax.swing.GroupLayout.Alignment.LEADING)
                                                        .addComponent(keyDecryptLabel,
                                                                javax.swing.GroupLayout.Alignment.LEADING)
                                                        .addComponent(verifyCheckBox,
                                                                javax.swing.GroupLayout.Alignment.LEADING)
                                                        .addComponent(verifyLabel,
                                                                javax.swing.GroupLayout.Alignment.LEADING)
                                                        .addComponent(decyptButton,
                                                                javax.swing.GroupLayout.Alignment.LEADING)
                                                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout
                                                                .createSequentialGroup()
                                                                .addComponent(decryptFromFileCheckBox)
                                                                .addPreferredGap(
                                                                        javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                        Short.MAX_VALUE)
                                                                .addComponent(openDecryptButton))
                                                        .addComponent(verifyTextField,
                                                                javax.swing.GroupLayout.Alignment.LEADING))
                                                        .addGap(0, 4, Short.MAX_VALUE))
                                                .addGroup(layout.createSequentialGroup().addComponent(jLabel3)
                                                        .addPreferredGap(
                                                                javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                        .addComponent(dateTextField))))
                                .addGroup(layout.createSequentialGroup().addComponent(jButton3).addGap(0, 0,
                                        Short.MAX_VALUE)))
                        .addContainerGap()));
        layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup().addContainerGap().addGroup(layout
                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup().addGroup(layout
                                .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel1)
                                .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel3).addComponent(dateTextField,
                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(jLabel2).addComponent(jTextField2,
                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(layout.createSequentialGroup().addComponent(decryptCheckBox)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(keyDecryptLabel)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(keyDecryptTextField,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addGroup(layout
                                                        .createParallelGroup(
                                                                javax.swing.GroupLayout.Alignment.BASELINE)
                                                        .addComponent(openDecryptButton)
                                                        .addComponent(decryptFromFileCheckBox))
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(decyptButton).addGap(14, 14, 14)
                                                .addComponent(verifyCheckBox)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(verifyLabel)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(verifyTextField,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addGroup(layout
                                                        .createParallelGroup(
                                                                javax.swing.GroupLayout.Alignment.BASELINE)
                                                        .addComponent(openVerifyButton)
                                                        .addComponent(verifyFromFileCheckBox))
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(verifyButton).addGap(0, 0, Short.MAX_VALUE))
                                        .addComponent(jScrollPane2)))
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 464, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jButton1).addComponent(jButton2).addComponent(jButton3))
                        .addContainerGap()));
    }// </editor-fold>//GEN-END:initComponents

    private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField1ActionPerformed

    private void decryptCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_decryptCheckBoxActionPerformed
        // TODO add your handling code here:
        boolean b = decryptCheckBox.isSelected();
        keyDecryptLabel.setEnabled(b);
        keyDecryptTextField.setEnabled(b);
        decryptFromFileCheckBox.setEnabled(b);
        fromFileDecrypt(decryptFromFileCheckBox.isSelected());
    }//GEN-LAST:event_decryptCheckBoxActionPerformed

    private void decryptFromFileCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_decryptFromFileCheckBoxActionPerformed
        // TODO add your handling code here:
        fromFileDecrypt(decryptFromFileCheckBox.isSelected());
    }//GEN-LAST:event_decryptFromFileCheckBoxActionPerformed

    private void openDecryptButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_openDecryptButtonActionPerformed
        // TODO add your handling code here:
        JFileChooser chooser = new JFileChooser();
        int retrieval = chooser.showOpenDialog(null);
        if (retrieval == JFileChooser.APPROVE_OPTION) {
            File file = chooser.getSelectedFile();
            Path path = Paths.get(file.getAbsolutePath());
            try {
                key = Files.readAllBytes(path);
                keyDecryptTextField.setText(key.toString());
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }
    }//GEN-LAST:event_openDecryptButtonActionPerformed

    private void verifyCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_verifyCheckBoxActionPerformed
        // TODO add your handling code here:
        boolean b = verifyCheckBox.isSelected();
        verifyLabel.setEnabled(b);
        verifyTextField.setEnabled(b);
        verifyFromFileCheckBox.setEnabled(b);
        fromFileVerify(verifyFromFileCheckBox.isSelected());
    }//GEN-LAST:event_verifyCheckBoxActionPerformed

    private void verifyFromFileCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_verifyFromFileCheckBoxActionPerformed
        // TODO add your handling code here:
        fromFileVerify(verifyFromFileCheckBox.isSelected());
    }//GEN-LAST:event_verifyFromFileCheckBoxActionPerformed

    private void fromFileDecrypt(boolean b) {
        if (decryptFromFileCheckBox.isEnabled()) {
            keyDecryptTextField.setEnabled(!b);
            openDecryptButton.setEnabled(b);
        } else {
            keyDecryptTextField.setEnabled(false);
            openDecryptButton.setEnabled(false);
        }
    }

    private void fromFileVerify(boolean b) {
        if (verifyFromFileCheckBox.isEnabled()) {
            verifyTextField.setEnabled(!b);
            openVerifyButton.setEnabled(b);
        } else {
            verifyTextField.setEnabled(false);
            openVerifyButton.setEnabled(false);
        }
    }

    private void openVerifyButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_openVerifyButtonActionPerformed
        JFileChooser chooser = new JFileChooser();
        int retrieval = chooser.showOpenDialog(null);
        FileNameExtensionFilter filter = new FileNameExtensionFilter("Public file", "pub");
        chooser.setFileFilter(filter);
        if (retrieval == JFileChooser.APPROVE_OPTION) {
            FileInputStream fis = null;
            try {
                File file = chooser.getSelectedFile();
                Path path = Paths.get(file.getAbsolutePath());
                fis = new FileInputStream(file);
                //Construct BufferedReader from InputStreamReader
                BufferedReader br = new BufferedReader(new InputStreamReader(fis));
                try {
                    String x = br.readLine();
                    String y = br.readLine();
                    publickey = new BigPoint(new BigInteger(x), new BigInteger(y));
                    System.out.println("Public key : " + publickey.getX() + publickey.getY());
                    br.close();
                } catch (IOException ex) {
                    Logger.getLogger(InboxPanel.class.getName()).log(Level.SEVERE, null, ex);
                }
            } catch (FileNotFoundException ex) {
                Logger.getLogger(InboxPanel.class.getName()).log(Level.SEVERE, null, ex);
            } finally {
                try {
                    fis.close();
                } catch (IOException ex) {
                    Logger.getLogger(InboxPanel.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
    }//GEN-LAST:event_openVerifyButtonActionPerformed

    private boolean isFileDecrypt() {
        return decryptCheckBox.isSelected() && decryptFromFileCheckBox.isEnabled()
                && decryptFromFileCheckBox.isSelected();
    }

    private boolean isFileSign() {
        return verifyCheckBox.isSelected() && verifyFromFileCheckBox.isEnabled()
                && verifyFromFileCheckBox.isSelected();
    }

    private void generateKey() {
        if (isFileDecrypt()) {

        } else {
            key = keyDecryptTextField.getText().getBytes();
        }
    }

    private String getTextBody() {
        String html = BodyTextPane.getText();
        Document doc = Jsoup.parseBodyFragment(html);
        Element body = doc.body();
        return body.text();
    }

    private void setTextBody(String sbody) {
        String html = BodyTextPane.getText();
        Document doc = Jsoup.parseBodyFragment(html);
        //Element body = doc.body();
        //body.text(sbody);
        doc.select("body").html(sbody);
        BodyTextPane.setText(doc.html());
    }

    private String getSign() {
        String html = BodyTextPane.getText();
        Document doc = Jsoup.parseBodyFragment(html);
        if (doc.select("ds") != null) {
            //System.out.println("Signature : \n" + doc.select("ds").text());
            return doc.select("ds").text();
        }
        return null;
    }

    private String[] getSignature(String sign) {
        String[] ret = new String[2];
        int offset = 0;
        while (sign.charAt(offset) < 'a' || sign.charAt(offset) > 'z' || sign.charAt(offset) < '0'
                || sign.charAt(offset) > '9') {
            offset++;
        }
        String string1 = "";
        String string2 = "";
        while (sign.charAt(offset) >= 'a' || sign.charAt(offset) <= 'z' || sign.charAt(offset) >= '0'
                || sign.charAt(offset) <= '9') {
            string1 += sign.charAt(offset);
            offset++;
        }
        while (sign.charAt(offset) < 'a' || sign.charAt(offset) > 'z' || sign.charAt(offset) < '0'
                || sign.charAt(offset) > '9') {
            offset++;
        }
        while ((sign.charAt(offset) >= 'a' || sign.charAt(offset) <= 'z' || sign.charAt(offset) >= '0'
                || sign.charAt(offset) <= '9') && offset < sign.length()) {
            string2 += sign.charAt(offset);
            offset++;
        }
        ret[0] = string1;
        ret[1] = string2;
        return ret;
    }

    private String getPlain() {
        String html = BodyTextPane.getText();
        Document doc = Jsoup.parseBodyFragment(html);
        doc.select("ds").remove();

        System.out.println("DS nya diilangin : \n" + doc.select("body").html());

        return doc.select("body").html();
    }

    private void showMsgDialog(String title, String message) {
        JOptionPane.showMessageDialog(null, message, title, JOptionPane.INFORMATION_MESSAGE);
    }

    private void decyptButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_decyptButtonActionPerformed
        // TODO add your handling code here:
        generateKey();
        cipher = Base64.decodeBase64(getTextBody());
        System.out.println("Isi message : \n" + BodyTextPane.getText());
        plain = BlockCipher.decryptCBC(cipher, StringByteModifier.md5Hash(key));
        message = new String(plain);
        System.out.println("\nHasil enkrip : \n" + new String(plain));
        //setTextBody(new String(plain));
        BodyTextPane.setText(new String(plain));
    }//GEN-LAST:event_decyptButtonActionPerformed

    private void verifyButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_verifyButtonActionPerformed
        // TODO add your handling code here:
        try {
            String text = BodyTextPane.getText();
            System.out.println("Verify text :\n" + text);
            String sign = text.substring(text.indexOf("<ds>") + 4, text.indexOf("</ds>"));
            String plai = text.substring(0, text.indexOf("<ds>"));

            //sign = sign.substring(4, sign.length()-5);
            String[] temp = sign.split("\n");
            System.out.println("Signature : " + temp[0] + ", " + temp[1]);
            BigPoint signature = new BigPoint(new BigInteger(temp[0], 16), new BigInteger(temp[1], 16));

            ECDSA ecdsa = new ECDSA();
            if (ecdsa.verify(plai, signature, publickey)) {
                //System.out.println("Verifikasi benar !");
                showMsgDialog("Verifikasi", "Verifikasi benar!");
            } else {
                showMsgDialog("Verifikasi", "Verifikasi salah!");
            }
        } catch (Exception e) {
            showMsgDialog("Verifikasi", "Verifikasi salah!");
        }

        //        ECDSA ecdsa = new ECDSA();

        /*String sign = getSign();
        System.out.println("Signature : " + sign);
        if (sign != null) {
        String [] temp = sign.split(" ");
        System.out.println("Signature : \n");
        for(int i=0; i<temp.length; i++) {
            System.out.println(i + " " + temp[i] + " ");
            temp[i] = temp[i].trim();
        }
        if (temp[0].length() == 0 || temp[1].length() == 0) {
            showMsgDialog("Verifikasi", "Tidak ada tanda tangan digital!");
            return;
        }
        System.out.println();
        BigPoint signature = new BigPoint(new BigInteger(temp[0], 16), new BigInteger(temp[1], 16));
        //String text = getPlain();
        String text = message;
        ECDSA ecdsa = new ECDSA();
        if(ecdsa.verify(text, signature, publickey)) {
            //System.out.println("Verifikasi benar !");
            showMsgDialog("Verifikasi", "Verifikasi benar!");
        } else {
            showMsgDialog("Verifikasi", "Verifikasi salah!");
        }
        } else {
        System.out.println("Signature null!");
        }*/
    }//GEN-LAST:event_verifyButtonActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        try {
            String name = GmailAPI.getAttachmentFilename(curId);
            System.out.println(name);
            if (name == "None") {
                JOptionPane.showMessageDialog(this, "No file attached on this email");
            } else {
                JFileChooser chooser = new JFileChooser();
                File defFile = new File(name);
                chooser.setSelectedFile(defFile);
                int filesave = chooser.showSaveDialog(null);
                if (filesave == JFileChooser.APPROVE_OPTION) {
                    //chooser.getSelectedFile().se
                    File file = chooser.getCurrentDirectory();
                    GmailAPI.getAttachments(GmailAPI.service, GmailAPI.USER, curId, file.getAbsolutePath(),
                            chooser.getSelectedFile().getName());
                }
            }
        } catch (IOException ex) {
            Logger.getLogger(InboxPanel.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_jButton3ActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextArea BodyTextPane;
    private javax.swing.JList InboxList;
    private javax.swing.JTextField dateTextField;
    private javax.swing.JCheckBox decryptCheckBox;
    private javax.swing.JCheckBox decryptFromFileCheckBox;
    private javax.swing.JButton decyptButton;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JLabel keyDecryptLabel;
    private javax.swing.JTextField keyDecryptTextField;
    private javax.swing.JButton openDecryptButton;
    private javax.swing.JButton openVerifyButton;
    private javax.swing.JButton verifyButton;
    private javax.swing.JCheckBox verifyCheckBox;
    private javax.swing.JCheckBox verifyFromFileCheckBox;
    private javax.swing.JLabel verifyLabel;
    private javax.swing.JTextField verifyTextField;
    // End of variables declaration//GEN-END:variables
}