diff --git a/SafeBoxDecryptor/bin/BoxFileZipUtils.class b/SafeBoxDecryptor/bin/BoxFileZipUtils.class new file mode 100644 index 0000000..03331d0 Binary files /dev/null and b/SafeBoxDecryptor/bin/BoxFileZipUtils.class differ diff --git a/SafeBoxDecryptor/bin/BoxFilter.class b/SafeBoxDecryptor/bin/BoxFilter.class new file mode 100644 index 0000000..1f0255f Binary files /dev/null and b/SafeBoxDecryptor/bin/BoxFilter.class differ diff --git a/SafeBoxDecryptor/bin/Main.class b/SafeBoxDecryptor/bin/Main.class new file mode 100644 index 0000000..ee56e28 Binary files /dev/null and b/SafeBoxDecryptor/bin/Main.class differ diff --git a/SafeBoxDecryptor/src/BoxFileZipUtils.java b/SafeBoxDecryptor/src/BoxFileZipUtils.java new file mode 100644 index 0000000..ac5eb9c --- /dev/null +++ b/SafeBoxDecryptor/src/BoxFileZipUtils.java @@ -0,0 +1,47 @@ +import java.io.BufferedInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.Scanner; +import java.util.zip.ZipEntry; +import java.util.zip.ZipException; +import java.util.zip.ZipFile; +import java.util.zip.ZipInputStream; + +import org.json.JSONObject; + + +public class BoxFileZipUtils { + private ZipFile zis; + public BoxFileZipUtils(File f) throws IOException { + zis = new ZipFile(f); + } + public JSONObject getDetails() throws IOException { + InputStream in = zis.getInputStream(this.zis.getEntry("meta.json")); + Scanner s = new Scanner(in).useDelimiter("\\A"); + String result = s.hasNext() ? s.next() : ""; + JSONObject obj = new JSONObject(result); + s.close(); + return obj; + } + public boolean extract(String fn,File outfile) throws IOException { + return this.extractContentFile(this.zis.getEntry(fn),outfile); + } + public boolean extractContentFile(ZipEntry e,File outfile) throws IOException { + if(e==null) return false; + if(e.isDirectory()) return false; + InputStream s =zis.getInputStream(e); + FileOutputStream fos = new FileOutputStream(outfile); + byte[] buffer = new byte[1024]; + int len; + while ((len = s.read(buffer)) > 0) { + fos.write(buffer, 0, len); + } + fos.close(); + return true; + } + +} diff --git a/SafeBoxDecryptor/src/BoxFilter.java b/SafeBoxDecryptor/src/BoxFilter.java new file mode 100644 index 0000000..93b0092 --- /dev/null +++ b/SafeBoxDecryptor/src/BoxFilter.java @@ -0,0 +1,19 @@ +import java.io.File; + +import javax.swing.filechooser.FileFilter; + +public class BoxFilter extends FileFilter{ + + @Override + public boolean accept(File f) { + // TODO Auto-generated method stub + if(f.isDirectory()) return true; + return f.getName().endsWith(".sfbx"); + } + + @Override + public String getDescription() { + return "SafeBox Archives"; + } + +} diff --git a/SafeBoxDecryptor/src/Main.java b/SafeBoxDecryptor/src/Main.java new file mode 100644 index 0000000..36d2e77 --- /dev/null +++ b/SafeBoxDecryptor/src/Main.java @@ -0,0 +1,194 @@ +import java.awt.Font; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.GridLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.io.File; +import java.io.IOException; +import java.time.Instant; +import java.util.ArrayList; + +import javax.swing.JButton; +import javax.swing.JFileChooser; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTextArea; +import javax.swing.JTextField; +import javax.swing.SwingConstants; + +import org.json.JSONObject; + +import net.lingala.zip4j.ZipFile; +import net.lingala.zip4j.exception.ZipException; + +public class Main extends JFrame implements ActionListener{ + private JLabel chooseFiletitle,chooseFileSubTitle,fileInfoTitle,fileInfoAuthor,fileInfoCreatedDate,fileInfoNKeys,outOf,keyLabel; + private JTextArea fileInfoMessage; + private JScrollPane fileInfoMessageScrollPane; + private int nkeys; + private JTextField key; + private JButton chooseFileButton,fileInfoOpen,fileInfoBack,next,redo,finish; + private JPanel chooseFile,fileInfo,keys; + private BoxFileZipUtils bfzu; + + public void initComponents() { + //title= new JLabel("SafeBox v 1.0"); + this.setTitle("SafeBox v 1.0"); + keyLabel = new JLabel("Key: "); + outOf= new JLabel("x out of y"); + key= new JTextField(20); + next= new JButton("Next"); + redo= new JButton("Redo"); + finish= new JButton("Finish"); + + chooseFile = new JPanel(); + chooseFile.setLayout(new GridLayout(3,2)); + chooseFiletitle= new JLabel("SafeBox v 1.0"); + chooseFiletitle.setHorizontalAlignment(SwingConstants.CENTER); + chooseFiletitle.setFont(new Font("Serif", Font.PLAIN,30)); + chooseFileSubTitle= new JLabel("Decryption utility"); + chooseFileSubTitle.setHorizontalAlignment(SwingConstants.CENTER); + chooseFileSubTitle.setFont(new Font("Serif", Font.PLAIN,15)); + chooseFileButton= new JButton("Open Safe"); + + chooseFile.add(chooseFiletitle); + chooseFile.add(chooseFileSubTitle); + chooseFile.add(chooseFileButton); + chooseFile.setVisible(true); + chooseFileButton.addActionListener(this); + this.add(chooseFile); + + } + private void fileChoose() { + JFileChooser jfc = new JFileChooser(); + jfc.setFileFilter(new BoxFilter()); + jfc.setAcceptAllFileFilterUsed(false); + int rv= jfc.showOpenDialog(this); + if(rv != JFileChooser.APPROVE_OPTION) System.exit(1); + File file = jfc.getSelectedFile(); + try { + bfzu= new BoxFileZipUtils(file); + JSONObject j= bfzu.getDetails(); + this.fileInfoCreatedDate= new JLabel(Instant.ofEpochSecond(j.getLong("unixcreated")).toString()); + this.fileInfoTitle= new JLabel(j.getString("title")); + this.fileInfoAuthor= new JLabel(j.getString("author")); + this.fileInfoMessage= new JTextArea(j.getString("message")); + this.nkeys=j.getInt("nkeys"); + this.fileInfoNKeys=new JLabel(String.valueOf(this.nkeys)); + this.fileInfoMessageScrollPane= new JScrollPane(this.fileInfoMessage); + this.fileInfoOpen= new JButton("Open Safe"); + this.fileInfoBack= new JButton("Back"); + this.fileInfo = new JPanel(); + this.fileInfo.setLayout(new GridLayout(6,1)); + this.fileInfo.add(fileInfoTitle); + this.fileInfo.add(fileInfoAuthor); + this.fileInfo.add(this.fileInfoCreatedDate); + this.fileInfo.add(fileInfoMessageScrollPane); + this.fileInfo.add(this.fileInfoOpen); + this.fileInfo.add(this.fileInfoBack); + this.chooseFile.hide(); + this.add(this.fileInfo); + this.fileInfo.show(); + this.fileInfoOpen.addActionListener(this); + this.fileInfoBack.addActionListener(this); + + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + JOptionPane.showMessageDialog(this, + "The selected file is corrupted", + "Error", + JOptionPane.ERROR_MESSAGE); + } + + } + private ArrayList getKeys(){ + ArrayList s = new ArrayList(); + for(int i=0;i