Professional Documents
Culture Documents
Issr3a Merged
Issr3a Merged
A PROJECT REPORT
for
in
by
DIVAKAR.M (19MIS0071)
Prof. BRINDHA K
PROBLEM STATEMENT
9b71d224bd62f3785d96d46ad3ea3d73319bfbc2890caadae2dff72519673ca7232
3c3d99b a5c11d7c7acc6e14b8c5da0c4663475c2e5c3adef46f73bcdec043
This hash is saved with the encrypted file. Anyone with this file will not be able
to retrieve the original password from the hash, even after trying all day (unless,
of course, the password used to encrypt it was weak). During decryption, the
hash of the entered password is compared with the hash of the original password
stored with the file during encryption. Only if they match will decryption start
with the newly entered password.
In this project, we are using the Java Class Library to develop in a 64-bit
windows platform using NetBeans IDE.
INTRODUCTION
With the help of this software, we may execute ENCRYPTION and encrypt our
preferred video, audio, text, executable, PDF, and other file types. In this
method, files like movies, music, PDFs, documents, photos, etc. won't open
without your password. There won't be any executable files available for
execution.
LITERATURE SURVEY
Annu Priya, Keshav Sinha, Manu Priya Darshani & Sudip Kumar
Sahana
The encryption manner is the technique such that a regular simple textual
content is coded in diverse approaches the usage of distinct algorithms in order
that the information receives unreadable and may simplest be examine through
deciphering the information the usage of decryption techniques. Encryption is
important for acquiring information integrity and safety. It allows with stable
information glide in any network. So, for the duration of this encryption
manifestly we can be experiencing a few overheads. This paper specializes in
the distinct encryption techniques and algorithms and the way every set of rules
behaves with distinct styles of documents together with textual content record,
MP3, PNG etc. The algorithms used had been AES, DES, RSA, and any other
encryption set of rules which become formulated through ourselves. The
execution time and the distinction withinside the record length become
measured. Graphs had been plotted for that reason and the measured portions
had been compared.
a a b c
LiYang ,ZiyiHan ,ZhenganHuang ,JianfengMa
The storage and computing capacity limitations of a mobile terminal pare down
the file sharing ability between mobile terminals and public clouds. The security
of public clouds increases perceived risks. Private clouds represent a very
effective platform and can be regarded as a trusted third party for improving the
level of security when a user uses a file from public clouds, we say. When a
mobile terminal uses data, the private clouds verify the integrity of the data in
the public clouds. The mobile terminal and private clouds decrypt the ciphertext
file to allow the user of the mobile terminal to use the data. In addition, we
analyse the security of FREDP using BAN.
HARDWARE REQUIREMENTS
• Memory: 6 GB RAM
SOFTWARE REQUIREMENTS
MainPage: Main page or welcome page is the first module of the project which
gets the input from the user whether he/she wants to encrypt or decrypt the file.
FileChooser: This module initiates the process of selecting any files of user
choice for encryption or decryption.
ARCHITECTURE
LOW-LEVEL DESIGN
HIGH-LEVEL DESIGN
PROPOSED SYSTEM
The primary weakness of the Vigenere cipher is the repeating nature of its key,
so if the period of key is greater than plain text we can increase the security of
the Vigenère cipher. This system generates large key from short keyword using
LFSR concept and mitigates the weaknesses of individual ciphers like Kasiski
and Index of Coincidence attacks. A novel approach is presented by combing
the LFSR key with Vigenère cipher key.
Stream ciphers, like Vigenère and Caesar require only one round of encryption
and decryption. Vigenere ciphers are very good at the confusion aspect of the
cryptography, but they lack the benefit of diffusion. Diffusion means making
the correlation between the cipher text and plain text as complex as possible.
The number of random bits is determined by a one-way function, F(x),
consisting of a prime p, a generator less than p and a positive constant less than
eight c. Vigenère ciphers are very good at the confusion aspect of cryptography,
but they lack the benefit of diffusion.
If random numbers are used for keys that increases the difficulty to decipher the
message. In conventional Vigenere Cipher the plaintext is considered as a
sequence of alphabets without any space between them. The converted sentence
may or may not form a meaningful one, because the receiver needs to guess the
exact place to insert space in decrypted plaintext.
IMPLEMENTATION
MAIN PAGE:
ENCRYPTION
SELECT FILES:
SELECT MUTIPLE FILES:
ASSIGN PASSWORD:
TO BE ENCRYPTED:
DECRYPTING:
SELECT THE FILES:
ENTER THE PASSWORD FOR DECRYPTION:
EXIT PAGE:
With this software we can perform ENCRYPTION and encrypt our video files,
audio files, text files, executable files, pdf, or any other file of our choice. This
way, without your password, files such as movies, music, pdf, documents,
images, etc. won't open. Executable files will no longer be in a state to be
executed. It is also other way around. With the password we had used for
encryption we can perform Decryption and convert our files back to their
original form. Moreover, the application does NOT store our passwords.
Instead, it uses SHA-512 hashing algorithm to verify the password Future work
will be adding more security with adding of more cryptography algorithms and
boost performance with SHA2_512 hashing algorithm.
References:
Panda, M. (2016). Performance analysis of encryption algorithms for security. 2016
International Conference on Signal Processing, Communication, Power and Embedded System
(SCOPES), 278-284.
Gandhi, Rashmi & Gonsai, Atul. (2015). A Study on Current Scenario of Audio Encryption.
International Journal of Computer Applications. 116. 13-17. 10.5120/20347-2533.
Dhany, H.W., Izhari, F., Fahmi, H., Tulus, & Sutarman (2018). Encryption and Decryption using
Password Based Encryption, MD5, and DES.
Li, Y., Yeli, L., & Liang-bin, Z. (2011). Transparent encryption based on network file system
filtering driver. 2011 International Conference on Electric Information and Control Engineering,
6339-6342.
Ahmad, I., & Das, A.S. (2007). Analysis and Detection Of Errors In Implementation Of SHA-
512 Algorithms On FPGAs. Comput. J., 50, 728-738.
Priya, Annu & Sinha, Keshav & Priyadarshani, Manu & Sahana, Sudip. (2019). A Novel Multimedia
Encryption and Decryption Technique Using Binary Tree Traversal. 10.1007/978-981-10-8234-4_15.
A. Kaur and G. Singh, “A Random Selective Block Encryption Technique For Secure Image
Cryptography Using Blowfish Algorithm,” IEEE Proc. Int. Conf. on Inventive Communication
and Computational Technologies, ICICCT 2018, no. Icicct, pp. 1290–1293, 2018
G. Singh and M. Garg, “Enhanced Cloud Security Using Hybrid Mechanism of RSA, AES
and Blowfish Data Encryption With Secure OTP,” Int. J. of Computers and Technology, vol.
18, pp. 7364–7380, 2018.
Appendix
Complete source code
EncryptorAndDecryptor.java
package core;
import gui.EncryptorAndDecryptorProgress;
import gui.ExceptionDialog;
import java.awt.Toolkit;
import java.io.File;
import javax.swing.*;
/**
*
* @author Jagadeesh Kowshik Deveshwar
*/
String encryptOrDecrypt;
String key;
FileEncryptorAndDecryptor fileEncryptorAndDecryptor;
int totalNumberOfFiles;
long totalSizeOfAllFiles;
boolean completedTask;
JProgressBar progressBar;
JTextArea progressOfFilesTextField;
JLabel progressPercentLabel;
JButton oKButton;
EncryptorAndDecryptorProgress progressFrame;
public EncryptorAndDecryptor(
21
File[] listOfFilesAndFolders,
String encryptOrDecrypt,
String key
) {
this.listOfFilesAndFolders = listOfFilesAndFolders;
this.encryptOrDecrypt = encryptOrDecrypt;
this.key = key;
progressBar = progressFrame.getProgressBar();
progressOfFilesTextField = progressFrame.getProgressOfFilesTextField();
progressPercentLabel = progressFrame.getProgressPercentLabel();
oKButton = progressFrame.getoKButton();
setTotalSizeAndNumberOfAllFiles();
@Override
try {
if (encryptOrDecrypt.equalsIgnoreCase("encrypt")) {
encrypt();
} else if (encryptOrDecrypt.equalsIgnoreCase("decrypt")) {
decrypt();
}
} catch (Exception e) {
new ExceptionDialog(
22
"Unexpected System Error!",
.setVisible(true);
} finally {
return true;
}
}
progressFrame.setCompletedTask(true);
Toolkit.getDefaultToolkit().beep();
oKButton.setVisible(true);
oKButton.setEnabled(true);
oKButton.setText("OK");
} catch (Exception e) {
new ExceptionDialog(
e
)
.setVisible(true);
}
}
23
private void encrypt() {
progressBar.setValue(progressBar.getMaximum());
progressPercentLabel.setText("100%");
progressOfFilesTextField.append(
"Encrypting " + file.getAbsolutePath() + "\n"
);
fileEncryptorAndDecryptor.encrypt(
file,
key,
progressBar,
progressPercentLabel,
totalSizeOfAllFiles,
progressOfFilesTextField
);
progressOfFilesTextField.append("Done!\n\n");
} else if (file.isDirectory() && file.exists()) {
file.getAbsolutePath() +
24
" ~~~~~~~~~~~~~~~~~~~~\n"
);
for (File eachFileInTheDirectory : filesInTheDirectory) {
encrypt(eachFileInTheDirectory);
}
progressOfFilesTextField.append(
file.getAbsolutePath() +
" ~~~~~~~~~~~~~~~~~~~~\n\n"
);
}
}
decrypt(file);
}
progressBar.setValue(progressBar.getMaximum());
progressPercentLabel.setText("100%");
!file.isDirectory() &&
file.exists() &&
file
.getName()
25
.substring(file.getName().length() - 4, file.getName().length())
.equalsIgnoreCase(".enc")
) {
progressOfFilesTextField.append(
fileEncryptorAndDecryptor.decrypt(
file,
key,
progressBar,
progressPercentLabel,
totalSizeOfAllFiles,
progressOfFilesTextField
);
progressOfFilesTextField.append("Done!\n\n");
file.getAbsolutePath() +
" ~~~~~~~~~~~~~~~~~~~~\n"
);
for (File eachFileInTheDirectory : filesInTheDirectory) {
decrypt(eachFileInTheDirectory);
}
progressOfFilesTextField.append(
" ~~~~~~~~~~~~~~~~~~~~\n\n"
);
}
private void setTotalSizeAndNumberOfAllFiles(File file) {
totalNumberOfFiles++;
totalSizeOfAllFiles += file.length();
setTotalSizeAndNumberOfAllFiles(eachFileInTheDirectory);
}
}
}}
FileEncryptorAndDecryptor.java
package core;
27
import gui.ExceptionDialog;
import gui.SourceFileNotDeletedDuringDecryption;
import gui.SourceFileNotDeletedDuringEncryption;
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.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JLabel;
import javax.swing.JProgressBar;
import javax.swing.JTextArea;
/**
*
*/
public class FileEncryptorAndDecryptor {
);
//reading key hash from file
fileReader.close();
if (keyHashFromFile.toString().equals(keyHash)) {
return true;
}
return false;
byte[] keyHash;
byte[] keyHash;
16).substring(1));
}
String hashOfPassword = sb.toString();
String key,
JProgressBar progressBar,
JLabel progressPercentLabel,
long totalSizeOfAllFiles,
JTextArea progressOfFilesTextField
) {
30
byte[] keyHash;
double percentageOfFileCopied = 0;
if (!file.isDirectory()) {
try {
keyHash = getHashInBytes(key);
if (destinationFile.exists()) {
destinationFile.delete();
new FileInputStream(file.getAbsolutePath())
);
destinationFile,
true
);
fileWriter.write(keyHash, 0, 128);
int i = 0, keyCounter = 0;
i < bufferSize;
i++, keyCounter %= keySize
) {
buffer[i] += key.toCharArray()[keyCounter];
}
fileWriter.write(buffer, 0, bytesCopied);
100);
showProgressOnprogressOfFilesTextField(
progressOfFilesTextField,
percentageOfFileCopied,
bytesCopied,
fileLength
);
showProgressOnProgressBarAndProgressPercent(
progressBar,
progressPercentLabel,
bytesCopied,
totalSizeOfAllFiles
32
);
progressOfFilesTextField.setText(
progressOfFilesTextField
.getText()
.substring(0, progressOfFilesTextField.getText().length() - 5) +
"100%\n"
);
fileReader.close();
fileWriter.close();
if (!file.delete()) {
new SourceFileNotDeletedDuringEncryption(
new javax.swing.JFrame(),
true,
file.getAbsolutePath()
)
.setVisible(true);
}
} catch (NoSuchAlgorithmException e) {
new ExceptionDialog(
"NoSuchAlgorithmException!",
.setVisible(true);
33
Logger
.getLogger(FileEncryptorAndDecryptor.class.getName())
.log(Level.SEVERE, null, e);
} catch (SecurityException e) {
new ExceptionDialog(
"File Security Error!!!",
e
)
.setVisible(true);
} catch (FileNotFoundException e) {
new ExceptionDialog("File Not Found!!!", file + " not found!", e)
.setVisible(true);
} catch (IOException e) {
new ExceptionDialog(
.setVisible(true);
} catch (Exception e) {
new ExceptionDialog(
"Unexpected System Error!",
.setVisible(true);
34
}
}
}
File file,
String key,
JProgressBar progressBar,
JLabel progressPercent,
long totalSizeOfAllFiles,
JTextArea progressOfFilesTextField
) {
String keyHash;
double percentageOfFileCopied = 0;
if (!file.isDirectory()) {
try {
keyHash = getHashInString(key);
if (areHashesEqual(file, keyHash)) {
destinationFile =
new File(
file
.getAbsolutePath()
.toString()
.substring(0, file.getAbsolutePath().toString().length() -
4)
);
);
FileOutputStream fileWriter = new
FileOutputStream(destinationFile);
);
for (int i = 0; i < 128; i++) {
if (fileReader.available() > 0) {
fileReader.read();
}
for (
int i = 0, keyCounter = 0;
i < bufferSize;
buffer[i] -= key.toCharArray()[keyCounter];
}
fileWriter.write(buffer, 0, bytesCopied);
36
long fileLength = file.length();
percentageOfFileCopied +=
(((double) bytesCopied / fileLength) * 100);
showProgressOnprogressOfFilesTextField(
progressOfFilesTextField,
percentageOfFileCopied,
bytesCopied,
fileLength
);
showProgressOnProgressBarAndProgressPercent(
progressBar,
progressPercent,
bytesCopied,
totalSizeOfAllFiles
);
System.out.println(
progressOfFilesTextField.setText(
progressOfFilesTextField
.getText()
.substring(0, progressOfFilesTextField.getText().length() - 5)
+
"100%\n"
);
fileReader.close();
37
fileWriter.close();
if (!file.delete()) {
new SourceFileNotDeletedDuringDecryption(
new javax.swing.JFrame(),
true,
file.getAbsolutePath()
.setVisible(true);
}
progressOfFilesTextField.append(
"\nPassword is verified using SHA-512 (128 bit) hash.\nLooks
like the Input Password and the File Password differ!!\nEven if you bypass
the hash (somehow) you won't be able to read the file because the file is
encrypted at byte level.\nWithout the actual password you have no
);
}
} catch (NoSuchAlgorithmException e) {
new ExceptionDialog(
"NoSuchAlgorithmException!",
)
.setVisible(true);
Logger
.getLogger(FileEncryptorAndDecryptor.class.getName())
38
.log(Level.SEVERE, null, e);
} catch (SecurityException e) {
new ExceptionDialog(
.setVisible(true);
} catch (FileNotFoundException e) {
.setVisible(true);
} catch (IOException e) {
new ExceptionDialog(
)
.setVisible(true);
} catch (Exception e) {
new ExceptionDialog(
"Unexpected System Error!",
)
.setVisible(true);
}
}
39
}
JProgressBar progressBar,
JLabel progressPercent,
int bytesCopied,
long totalSizeOfAllFiles
) {
int previousProgress = progressBar.getValue();
if (accumulator >= 1) {
progressBar.setValue(percentage);
progressPercent.setText(Integer.toString(percentage) + "%");
}
private void showProgressOnprogressOfFilesTextField(
JTextArea progressOfFilesTextField,
double percentageOfFileCopied,
int bytesCopied,
long fileLength
) {
.getText()
.substring(0, progressOfFilesTextField.getText().length() - 5)
);
"%\n");
} else if (percentageOfFileCopied < 100) {
"%\n");
} else if (percentageOfFileCopied >= 100) {
progressOfFilesTextField.setText(s.toString());
}
}
Main.java
package gui;
import java.awt.Toolkit;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
41
/**
*
*/
public class Main extends javax.swing.JFrame {
setResizable(false);
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
addWindowListener(
new WindowAdapter() {
frame,
"Are you sure you want to exit the application?",
"Exit Application",
JOptionPane.YES_NO_OPTION
);
if (result == JOptionPane.YES_OPTION) {
if (usedTheApplication) {
42
new ThankYouDialog(new javax.swing.JFrame(), true)
.setVisible(rootPaneCheckingEnabled);
}
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
);
/**
* 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
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
heading.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
heading.setText(
"Welcome to File Encryption & Decryption Software (ISSA Project)"
);
jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
encryptButton.addActionListener(
new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
encryptButtonActionPerformed(evt);
44
}
}
);
decryptButton.addActionListener(
new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
decryptButtonActionPerformed(evt);
}
}
);
NOI18N
jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
jLabel4.setText("About!");
"is the option you select below, it takes all the files you choose and
all the sub-files of the folder(s) you choose,"
);
jLabel10.setText(
45
"Just click \"YES\" then this software is definitely encrypt any kind
"encrypts them with the password you enter and thus makes them
);
jLabel14.setText(
"Do you want your encrypted file(s) back in the original form ?"
);
jLabel16.setText(
"\"Decrypt My Files\" is the option you should select. It
);
jLabel17.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
jLabel17.setText(
" software does NOT store your passwords. Instead it uses SHA-512
hashing algorithm to verify the password."
);
);
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout
.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
javax.swing.GroupLayout.Alignment.TRAILING,
layout
.createSequentialGroup()
.addContainerGap(
javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE
)
.addGroup(
layout
47
.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADI
NG)
.addComponent(decryptButton)
.addComponent(encryptButton)
.addComponent(
jLabel1,
javax.swing.GroupLayout.PREFERRED_SIZE,
133,
javax.swing.GroupLayout.PREFERRED_SIZE
)
.addGap(281, 281, 281)
.addGroup(
layout
.createSequentialGroup()
.addContainerGap()
.addGroup(
layout
.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADI
NG)
.addGroup(
layout
.createSequentialGroup()
.addComponent(
jLabel4,
javax.swing.GroupLayout.PREFERRED_SIZE,
48
664,
javax.swing.GroupLayout.PREFERRED_SIZE
)
.addGap(0, 0, Short.MAX_VALUE)
)
.addGroup(
layout
.createSequentialGroup()
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING
.addComponent(
jLabel13,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE
.addComponent(
heading,
javax.swing.GroupLayout.Alignment.TRAILING,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE
)
.addComponent(
49
jLabel14,
javax.swing.GroupLayout.Alignment.TRAILING,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE
)
.addComponent(
jLabel11,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE
)
.addComponent(
jLabel12,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE
)
.addComponent(
jLabel15,
javax.swing.GroupLayout.Alignment.TRAILING,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE
)
.addComponent(
jLabel16,
50
javax.swing.GroupLayout.DEFAULT_SIZE,
673,
Short.MAX_VALUE
.addComponent(
jLabel17,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE
.addGroup(
layout
.createSequentialGroup()
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.TRAILING
,
false
)
.addComponent(
jLabel10,
javax.swing.GroupLayout.Alignment.LEADING,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE
)
51
.addComponent(
jLabel9,
javax.swing.GroupLayout.Alignment.LEADING,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE
)
.addGap(0, 0, Short.MAX_VALUE)
)
.addContainerGap()
)
)
);
layout.setVerticalGroup(
layout
.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
layout
.createSequentialGroup()
.addGap(19, 19, 19)
.addComponent(
heading,
javax.swing.GroupLayout.PREFERRED_SIZE,
26,
52
javax.swing.GroupLayout.PREFERRED_SIZE
)
.addGap(58, 58, 58)
.addComponent(jLabel4)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELA
TED)
.addComponent(jLabel9)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELA
TED)
.addComponent(jLabel11)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELA
TED)
.addComponent(jLabel12)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELA
TED)
.addComponent(jLabel13)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELA
TED)
.addComponent(jLabel15)
jLabel14,
javax.swing.GroupLayout.PREFERRED_SIZE,
27,
javax.swing.GroupLayout.PREFERRED_SIZE
53
)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELA
TED)
.addComponent(jLabel16)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELA
TED)
.addComponent(jLabel17)
jLabel1,
javax.swing.GroupLayout.PREFERRED_SIZE,
36,
javax.swing.GroupLayout.PREFERRED_SIZE
)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELA
TED)
.addComponent(encryptButton)
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.UNRELATED
)
.addComponent(decryptButton)
.addContainerGap(87, Short.MAX_VALUE)
)
);
pack();
} // </editor-fold>//GEN-END:initComponents
54
private void encryptButtonActionPerformed(java.awt.event.ActionEvent evt)
{ //GEN-FIRST:event_encryptButtonActionPerformed //GEN-
HEADEREND:event_encryptButtonActionPerformed
fileChooser.setVisible(true);
setVisible(false);
dispose();
} //GEN-LAST:event_encryptButtonActionPerformed
private void decryptButtonActionPerformed(java.awt.event.ActionEvent evt)
{ //GEN-FIRST:event_decryptButtonActionPerformed //GEN-
HEADEREND:event_decryptButtonActionPerformed
FileChooser fileChooser = new FileChooser("DECRYPT");
fileChooser.setVisible(true);
setVisible(false);
dispose();
} //GEN-LAST:event_decryptButtonActionPerformed
/**
*/
public static void main(String args[]) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
55
break;
}
}
java.util.logging.Logger
.getLogger(Main.class.getName())
.getLogger(Main.class.getName())
java.util.logging.Logger
.getLogger(Main.class.getName())
.log(java.util.logging.Level.SEVERE, null, ex);
java.util.logging.Logger
.getLogger(Main.class.getName())
}
//</editor-fold>
java.awt.EventQueue.invokeLater(
new Runnable() {
public void run() {
new Main(false).setVisible(true);
56
}
}
);
EncryptorAndDecryptorProgress.java
package gui;
import java.awt.Toolkit;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
57
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JProgressBar;
import javax.swing.JTextArea;
/**
*
* @author Jagadeesh Kowshik Deveshwar
*/
this.completedTask = completedTask;
}
this.encryptOrDecrypt = encryptOrDecrypt;
/* Set the Nimbus look and feel */
http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
58
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info :
javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
java.util.logging.Logger
.getLogger(EncryptorAndDecryptorProgress.class.getName())
.getLogger(EncryptorAndDecryptorProgress.class.getName())
java.util.logging.Logger
.getLogger(EncryptorAndDecryptorProgress.class.getName())
.log(java.util.logging.Level.SEVERE, null, ex);
.getLogger(EncryptorAndDecryptorProgress.class.getName())
.log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
59
/* Create and display the form */
initComponents();
setResizable(false);
progressOfFilesTextField.setEditable(false);
oKButton.setVisible(false);
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
addWindowListener(
new WindowAdapter() {
int result;
if (completedTask) {
Toolkit.getDefaultToolkit().beep();
result =
JOptionPane.showConfirmDialog(
frame,
"Exit Application",
JOptionPane.YES_NO_OPTION
);
if (result == JOptionPane.YES_OPTION) {
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
} else if (encryptOrDecrypt.equals("encrypt")) {
Toolkit.getDefaultToolkit().beep();
60
result =
JOptionPane.showConfirmDialog(
frame,
JOptionPane.YES_NO_OPTION
);
if (
result == JOptionPane.YES_OPTION
) frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
} else if (encryptOrDecrypt.equals("decrypt")) {
Toolkit.getDefaultToolkit().beep();
result =
JOptionPane.showConfirmDialog(
frame,
"Exit Application",
JOptionPane.YES_NO_OPTION
);
if (
result == JOptionPane.YES_OPTION
) frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
}
61
);
if (encryptOrDecrypt.equalsIgnoreCase("encrypt")) {
heading.setText("Encrypting:");
} else if (encryptOrDecrypt.equalsIgnoreCase("decrypt")) {
heading.setText("Decrypting:");
}
getRootPane().setDefaultButton(oKButton);
this.setVisible(true);
}
return progressBar;
return progressOfFilesTextField;
}
return progressPercentLabel;
}
/**
62
* 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
*/
@SuppressWarnings("unchecked")
BEGIN:initComponents
private void initComponents() {
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
progressOfFilesTextField.setRows(5);
progressOfFilesTextField.setToolTipText("OK");
jScrollPane1.setViewportView(progressOfFilesTextField);
progressPercentLabel.setHorizontalAlignment(
javax.swing.SwingConstants.RIGHT
);
progressPercentLabel.setText("0%");
63
oKButton.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
oKButton.setToolTipText("OK");
oKButton.setEnabled(false);
oKButton.addActionListener(
new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
oKButtonActionPerformed(evt);
}
}
);
);
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout
.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
layout
.createSequentialGroup()
.addContainerGap()
.addGroup(
layout
.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADI
NG)
.addComponent(
jScrollPane1,
64
javax.swing.GroupLayout.DEFAULT_SIZE,
708,
Short.MAX_VALUE
.addGroup(
layout
.createSequentialGroup()
.addComponent(heading)
.addGap(0, 0, Short.MAX_VALUE)
.addComponent(
progressBar,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE
.addGroup(
javax.swing.GroupLayout.Alignment.TRAILING,
layout
.createSequentialGroup()
.addGap(0, 0, Short.MAX_VALUE)
.addComponent(
oKButton,
javax.swing.GroupLayout.PREFERRED_SIZE,
88,
javax.swing.GroupLayout.PREFERRED_SIZE
)
65
.addGap(204, 204, 204)
.addComponent(
progressPercentLabel,
javax.swing.GroupLayout.PREFERRED_SIZE,
96,
javax.swing.GroupLayout.PREFERRED_SIZE
)
)
.addContainerGap()
)
);
layout.setVerticalGroup(
layout
.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
layout
.createSequentialGroup()
.addContainerGap()
.addComponent(heading)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELA
TED)
.addComponent(
jScrollPane1,
javax.swing.GroupLayout.PREFERRED_SIZE,
347,
javax.swing.GroupLayout.PREFERRED_SIZE
66
)
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED,
16,
Short.MAX_VALUE
)
.addComponent(
progressBar,
javax.swing.GroupLayout.PREFERRED_SIZE,
26,
javax.swing.GroupLayout.PREFERRED_SIZE
)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELA
TED)
.addGroup(
layout
.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADI
NG)
.addComponent(progressPercentLabel)
.addComponent(
oKButton,
javax.swing.GroupLayout.PREFERRED_SIZE,
31,
javax.swing.GroupLayout.PREFERRED_SIZE
)
)
);
pack();
} // </editor-fold>//GEN-END:initComponents
{ //GEN-FIRST:event_oKButtonActionPerformed //GEN-
HEADEREND:event_oKButtonActionPerformed
new Main(true).setVisible(true);
setVisible(false);
dispose();
} //GEN-LAST:event_oKButtonActionPerformed
FileChooser.java
package gui;
import java.awt.Toolkit;
import java.awt.event.WindowAdapter;
68
import java.awt.event.WindowEvent;
import java.io.File;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
/**
*
*/
public class FileChooser extends javax.swing.JFrame {
/**
this.encryptOrDecrypt = encryptOrDecrypt;
/* Set the Nimbus look and feel */
try {
for (javax.swing.UIManager.LookAndFeelInfo info :
javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
69
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger
.getLogger(FileChooser.class.getName())
.log(java.util.logging.Level.SEVERE, null, ex);
java.util.logging.Logger
.getLogger(FileChooser.class.getName())
.getLogger(FileChooser.class.getName())
java.util.logging.Logger
.getLogger(FileChooser.class.getName())
.log(java.util.logging.Level.SEVERE, null, ex);
//</editor-fold>
/* Create and display the form */
initComponents();
jFileChooser1.setDialogTitle(
"Select files & those folders whose files you wish to " +
encryptOrDecrypt
);
jFileChooser1.setMultiSelectionEnabled(true);
70
jFileChooser1.setFileSelectionMode(FILES_AND_DIRECTORIES);
jFileChooser1.setDialogTitle(encryptOrDecrypt);
if (encryptOrDecrypt.equalsIgnoreCase("encrypt")) {
UIManager.put(
"FileChooser.openDialogTitleText",
"Select Files To Encrypt"
);
} else if (encryptOrDecrypt.equalsIgnoreCase("decrypt")) {
UIManager.put(
"FileChooser.openDialogTitleText",
);
UIManager.put("FileChooser.openButtonText", "Select Files To
Decrypt");
}
UIManager.put("FileChooser.cancelButtonText", "Cancel");
UIManager.put("FileChooser.fileNameLabelText", "FileName");
UIManager.put("FileChooser.filesOfTypeLabelText", "TypeFiles");
UIManager.put("FileChooser.openButtonToolTipText", "Select File");
UIManager.put("FileChooser.cancelButtonToolTipText", "Cancel");
UIManager.put("FileChooser.fileNameHeaderText", "FileName");
UIManager.put("FileChooser.upFolderToolTipText", "UpOneLevel");
UIManager.put("FileChooser.homeFolderToolTipText", "Desktop");
UIManager.put("FileChooser.newFolderToolTipText", "Create a NewFolder");
UIManager.put("FileChooser.listViewButtonToolTipText", "List");
71
UIManager.put("FileChooser.filterLabelText", "TypeFiles");
UIManager.put("FileChooser.detailsViewButtonToolTipText", "Details");
UIManager.put("FileChooser.fileSizeHeaderText", "Size");
UIManager.put("FileChooser.fileDateHeaderText", "DateModified");
SwingUtilities.updateComponentTreeUI(jFileChooser1);
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
addWindowListener(
new WindowAdapter() {
setVisible(false);
dispose();
new Main(false).setVisible(true);
}
}
);
}
public FileChooser(String encryptOrDecrypt, File[] listOfFilesAndFolders)
this.encryptOrDecrypt = encryptOrDecrypt;
this.listOfFilesAndFolders = listOfFilesAndFolders;
addingNewFilesToExisting = true;
/* Set the Nimbus look and feel */
try {
for (javax.swing.UIManager.LookAndFeelInfo info :
javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
72
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
.getLogger(FileChooser.class.getName())
java.util.logging.Logger
.getLogger(FileChooser.class.getName())
.log(java.util.logging.Level.SEVERE, null, ex);
java.util.logging.Logger
.getLogger(FileChooser.class.getName())
.getLogger(FileChooser.class.getName())
//</editor-fold>
73
"Select files & those folders whose files you wish to " +
encryptOrDecrypt
);
jFileChooser1.setMultiSelectionEnabled(true);
jFileChooser1.setFileSelectionMode(FILES_AND_DIRECTORIES);
jFileChooser1.setDialogTitle(encryptOrDecrypt);
if (encryptOrDecrypt.equalsIgnoreCase("encrypt")) {
UIManager.put(
"FileChooser.openDialogTitleText",
);
UIManager.put("FileChooser.openButtonText", "Select Files To
Encrypt");
} else if (encryptOrDecrypt.equalsIgnoreCase("decrypt")) {
UIManager.put(
"FileChooser.openDialogTitleText",
Decrypt");
}
UIManager.put("FileChooser.cancelButtonText", "Cancel");
UIManager.put("FileChooser.fileNameLabelText", "FileName");
UIManager.put("FileChooser.filesOfTypeLabelText", "TypeFiles");
UIManager.put("FileChooser.openButtonToolTipText", "Select File");
UIManager.put("FileChooser.cancelButtonToolTipText", "Cancel");
UIManager.put("FileChooser.fileNameHeaderText", "FileName");
74
UIManager.put("FileChooser.upFolderToolTipText", "UpOneLevel");
UIManager.put("FileChooser.homeFolderToolTipText", "Desktop");
UIManager.put("FileChooser.newFolderToolTipText", "Create a NewFolder");
UIManager.put("FileChooser.listViewButtonToolTipText", "List");
UIManager.put("FileChooser.filterLabelText", "TypeFiles");
UIManager.put("FileChooser.detailsViewButtonToolTipText", "Details");
UIManager.put("FileChooser.fileSizeHeaderText", "Size");
UIManager.put("FileChooser.fileDateHeaderText", "DateModified");
SwingUtilities.updateComponentTreeUI(jFileChooser1);
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
addWindowListener(
new WindowAdapter() {
dispose();
new Main(false).setVisible(true);
}
);
}
filePath
75
.substring(filePath.length() - 4, filePath.length())
.equals(".enc")
) {
encrypted");
Toolkit.getDefaultToolkit().beep();
JOptionPane.showMessageDialog(
null,
"1 or more files are already encrypted !! \nPlease de-select
them."
);
return true;
}
return false;
!file.isDirectory() &&
!filePath
.substring(filePath.length() - 4, filePath.length())
.equals(".enc")
) {
JOptionPane.showMessageDialog(
null,
);
return false;
}
return true;
/**
* 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
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jFileChooser1.addActionListener(
new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jFileChooser1ActionPerformed(evt);
}
77
}
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(
getContentPane()
);
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout
.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(
jFileChooser1,
javax.swing.GroupLayout.Alignment.TRAILING,
javax.swing.GroupLayout.DEFAULT_SIZE,
602,
Short.MAX_VALUE
);
layout.setVerticalGroup(
layout
.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(
jFileChooser1,
javax.swing.GroupLayout.DEFAULT_SIZE,
419,
Short.MAX_VALUE
)
);
78
pack();
} // </editor-fold>//GEN-END:initComponents
private void jFileChooser1ActionPerformed(java.awt.event.ActionEvent evt)
{ //GEN-FIRST:event_jFileChooser1ActionPerformed //GEN-
HEADEREND:event_jFileChooser1ActionPerformed
if (evt.getActionCommand().toString().equals("CancelSelection")) {
if (addingNewFilesToExisting) {
new ToBeEncryptedOrDecrypted(
this.listOfFilesAndFolders,
encryptOrDecrypt
)
.setVisible(true);
setVisible(false);
dispose();
} else if (!addingNewFilesToExisting) {
new Main(false).setVisible(true);
setVisible(false);
dispose();
} else if (evt.getActionCommand().toString().equals("ApproveSelection"))
{
if (!addingNewFilesToExisting) {
this.listOfFilesAndFolders = jFileChooser1.getSelectedFiles();
} else if (addingNewFilesToExisting) {
File[] newFilesAndFolders = jFileChooser1.getSelectedFiles();
int newLength =
newFilesAndFolders.length + this.listOfFilesAndFolders.length;
79
File[] combinedFileArray = new File[newLength];
int i;
for (i = 0; i < this.listOfFilesAndFolders.length; i++) {
combinedFileArray[i] = this.listOfFilesAndFolders[i];
}
for (int j = 0; j < newFilesAndFolders.length; j++) {
combinedFileArray[i++] = newFilesAndFolders[j];
}
this.listOfFilesAndFolders = combinedFileArray;
if (
encryptOrDecrypt.equalsIgnoreCase("encrypt") &&
!anyEncFileExists(listOfFilesAndFolders)
) {
new ToBeEncryptedOrDecrypted(
this.listOfFilesAndFolders,
encryptOrDecrypt
)
.setVisible(true);
setVisible(false);
dispose();
} else if (
encryptOrDecrypt.equalsIgnoreCase("decrypt") &&
allAreEncFiles(listOfFilesAndFolders)
) {
new ToBeEncryptedOrDecrypted(listOfFilesAndFolders,
encryptOrDecrypt)
80
.setVisible(true);
setVisible(false);
dispose();
}
} //GEN-LAST:event_jFileChooser1ActionPerformed
ToBeEncryptedOrDecrypted.java
package gui;
import java.awt.Toolkit;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
/**
*
* @author Jagadeesh Kowshik Deveshwar
*/
public class ToBeEncryptedOrDecrypted extends javax.swing.JFrame {
81
public ToBeEncryptedOrDecrypted(
File[] listOfFilesAndFolders,
String encryptOrDecrypt
) {
this.listOfFilesAndFolders = listOfFilesAndFolders;
this.encryptOrDecrypt = encryptOrDecrypt;
try {
for (javax.swing.UIManager.LookAndFeelInfo info :
javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
java.util.logging.Logger
.getLogger(ToBeEncryptedOrDecrypted.class.getName())
.getLogger(ToBeEncryptedOrDecrypted.class.getName())
.log(java.util.logging.Level.SEVERE, null, ex);
java.util.logging.Logger
.getLogger(ToBeEncryptedOrDecrypted.class.getName())
}
initComponents();
setResizable(false);
listOfFilesAndFoldersTextField.setEditable(false);
if (encryptOrDecrypt.equalsIgnoreCase("encrypt")) {
encryptOrDecryptButton.setText("ENCRYPT");
heading.setText("List of files/folders to be encrypted:");
} else if (encryptOrDecrypt.equalsIgnoreCase("decrypt")) {
encryptOrDecryptButton.setText("DECRYPT");
heading.setText("List of files/folders to be decrypted:");
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
addWindowListener(
new WindowAdapter() {
public void windowClosing(WindowEvent e) {
"Exit Application",
83
JOptionPane.YES_NO_OPTION
);
if (result == JOptionPane.YES_OPTION)
frame.setDefaultCloseOperation(
JFrame.EXIT_ON_CLOSE
);
}
);
displayListOfFilesInTheTextField();
getRootPane().setDefaultButton(encryptOrDecryptButton);
listOfFilesAndFoldersTextField.append(
listOfFilesAndFoldersTextField.append(
listOfFilesAndFolders[i].getAbsolutePath() + "\n\n"
);
}
}
/**
* 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
84
VELLORE INSTITUTE OF TECHNOLOGY
*/
@SuppressWarnings("unchecked")
BEGIN:initComponents
private void initComponents() {
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
listOfFilesAndFoldersTextField.setColumns(20);
listOfFilesAndFoldersTextField.setRows(5);
jScrollPane1.setViewportView(listOfFilesAndFoldersTextField);
reSelectFilesButton.addActionListener(
new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
reSelectFilesButtonActionPerformed(evt);
85
VELLORE INSTITUTE OF TECHNOLOGY
}
);
addMoreFilesButton.addActionListener(
new java.awt.event.ActionListener() {
addMoreFilesButtonActionPerformed(evt);
}
);
// NOI18N
encryptOrDecryptButton.addActionListener(
new java.awt.event.ActionListener() {
}
);
);
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout
86
VELLORE INSTITUTE OF TECHNOLOGY
.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
layout
.createSequentialGroup()
.addContainerGap()
.addGroup(
layout
.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADI
NG)
.addComponent(
heading,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE
)
.addComponent(jScrollPane1)
.addGroup(
layout
.createSequentialGroup()
.addComponent(addMoreFilesButton)
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED,
80,
Short.MAX_VALUE
)
.addComponent(
encryptOrDecryptButton,
87
VELLORE INSTITUTE OF TECHNOLOGY
javax.swing.GroupLayout.PREFERRED_SIZE,
175,
javax.swing.GroupLayout.PREFERRED_SIZE
)
.addContainerGap()
);
layout.setVerticalGroup(
layout
.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
layout
.createSequentialGroup()
.addContainerGap(
javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE
)
.addComponent(heading)
.addGap(18, 18, 18)
.addComponent(
jScrollPane1,
javax.swing.GroupLayout.PREFERRED_SIZE,
347,
88
VELLORE INSTITUTE OF TECHNOLOGY
javax.swing.GroupLayout.PREFERRED_SIZE
)
.addGap(18, 18, 18)
.addGroup(
layout
.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADI
NG)
.addComponent(
addMoreFilesButton,
javax.swing.GroupLayout.Alignment.TRAILING
)
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.BASELINE
.addComponent(reSelectFilesButton)
.addComponent(encryptOrDecryptButton)
)
.addGap(22, 22, 22)
)
);
pack();
} // </editor-fold>//GEN-END:initComponents
private void addMoreFilesButtonActionPerformed(
java.awt.event.ActionEvent evt
89
) { //GEN-FIRST:event_addMoreFilesButtonActionPerformed //GEN-
HEADEREND:event_addMoreFilesButtonActionPerformed
for (File file : listOfFilesAndFolders) {
System.out.println(file);
new FileChooser(encryptOrDecrypt,
listOfFilesAndFolders).setVisible(true);
setVisible(false);
dispose();
} //GEN-LAST:event_addMoreFilesButtonActionPerformed
private void encryptOrDecryptButtonActionPerformed(
java.awt.event.ActionEvent evt
) { //GEN-FIRST:event_encryptOrDecryptButtonActionPerformed //GEN-
HEADEREND:event_encryptOrDecryptButtonActionPerformed
setVisible(false);
dispose();
if (encryptOrDecrypt.equalsIgnoreCase("encrypt")) {
new
PasswordTakerForEncryption(listOfFilesAndFolders).setVisible(true);
} else if (encryptOrDecrypt.equalsIgnoreCase("decrypt")) {
new
PasswordTakerForDecryption(listOfFilesAndFolders).setVisible(true);
}
} //GEN-LAST:event_encryptOrDecryptButtonActionPerformed
java.awt.event.ActionEvent evt
) { //GEN-FIRST:event_reSelectFilesButtonActionPerformed //GEN-
HEADEREND:event_reSelectFilesButtonActionPerformed
new FileChooser(encryptOrDecrypt).setVisible(true);
setVisible(false);
dispose();
} //GEN-LAST:event_reSelectFilesButtonActionPerformed
}
PasswordTakerForEncryption.java
package gui;
import core.EncryptorAndDecryptor;
import java.awt.Toolkit;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
import java.util.Arrays;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
91
VELLORE INSTITUTE OF TECHNOLOGY
this.listOfFilesAndFolders = listOfFilesAndFolders;
try {
for (javax.swing.UIManager.LookAndFeelInfo info :
javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
java.util.logging.Logger
.getLogger(ToBeEncryptedOrDecrypted.class.getName())
.getLogger(ToBeEncryptedOrDecrypted.class.getName())
java.util.logging.Logger
.getLogger(ToBeEncryptedOrDecrypted.class.getName())
.getLogger(ToBeEncryptedOrDecrypted.class.getName())
92
VELLORE INSTITUTE OF TECHNOLOGY
}
initComponents();
setResizable(false);
eightCharInstructionLabel.setVisible(false);
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
getRootPane().setDefaultButton(proceedButton);
addWindowListener(
new WindowAdapter() {
Toolkit.getDefaultToolkit().beep();
"Exit Application",
JOptionPane.YES_NO_OPTION
);
if (result == JOptionPane.YES_OPTION)
frame.setDefaultCloseOperation(
JFrame.EXIT_ON_CLOSE
);
}
}
);
93
VELLORE INSTITUTE OF TECHNOLOGY
boolean verifyPasswords() {
char password1[] = passwordField1.getPassword();
if (password1.length < 8) {
eightCharInstructionLabel.setText(
characters"
);
eightCharInstructionLabel.setVisible(true);
return false;
}
if (password1.length > 7) {
eightCharInstructionLabel.setVisible(false);
if (password1.length == password2.length) {
eightCharInstructionLabel.setVisible(false);
if (Arrays.equals(password1, password2)) {
return true;
}
eightCharInstructionLabel.setText("Both the passwords differ!");
eightCharInstructionLabel.setVisible(true);
}
return false;
}
@SuppressWarnings("unchecked")
94
VELLORE INSTITUTE OF TECHNOLOGY
BEGIN:initComponents
private void initComponents() {
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
passwordField1.addKeyListener(
new java.awt.event.KeyAdapter() {
passwordField1KeyReleased(evt);
}
}
);
95
VELLORE INSTITUTE OF TECHNOLOGY
passwordField2.setToolTipText("");
passwordField2.addKeyListener(
new java.awt.event.KeyAdapter() {
passwordField2KeyReleased(evt);
}
);
proceedButton.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
proceedButton.setText("Proceed");
proceedButton.setEnabled(false);
proceedButton.addActionListener(
new java.awt.event.ActionListener() {
}
);
suggestionLabel.setFont(
new java.awt.Font("Source Code Pro Semibold", 1, 16)
); // NOI18N
suggestionLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER
);
suggestionLabel.setText(
"The l o n g e r & STRONGER the password, the S E C U R E the file(s)"
);
96
VELLORE INSTITUTE OF TECHNOLOGY
);
eightCharInstructionLabel.setFocusable(false);
);
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout
.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
layout
.createSequentialGroup()
.addContainerGap()
.addGroup(
layout
.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADI
NG)
.addGroup(
layout
.createSequentialGroup()
.addGroup(
layout
97
VELLORE INSTITUTE OF TECHNOLOGY
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING
)
.addComponent(
passwordField2,
javax.swing.GroupLayout.Alignment.TRAILING
.addComponent(
passwordField1,
javax.swing.GroupLayout.Alignment.TRAILING
)
.addGroup(
layout
.createSequentialGroup()
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING
.addComponent(jLabel1)
.addComponent(jLabel2)
)
.addGap(0, 0, Short.MAX_VALUE)
)
.addComponent(
suggestionLabel,
javax.swing.GroupLayout.DEFAULT_SIZE,
98
javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE
)
.addContainerGap()
)
.addGroup(
javax.swing.GroupLayout.Alignment.TRAILING,
layout
.createSequentialGroup()
.addComponent(eightCharInstructionLabel)
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED,
javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE
.addComponent(proceedButton)
.addGap(395, 395, 395)
)
)
);
layout.setVerticalGroup(
layout
.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
layout
99
.createSequentialGroup()
.addContainerGap(
javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE
)
.addComponent(
suggestionLabel,
javax.swing.GroupLayout.PREFERRED_SIZE,
19,
javax.swing.GroupLayout.PREFERRED_SIZE
)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELA
TED)
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELA
TED)
.addComponent(
passwordField1,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE
)
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.UNRELATED
)
.addComponent(jLabel2)
100
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELA
TED)
.addComponent(
passwordField2,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE
)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELA
TED)
.addGroup(
layout
.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADI
NG)
.addComponent(
proceedButton,
javax.swing.GroupLayout.PREFERRED_SIZE,
28,
javax.swing.GroupLayout.PREFERRED_SIZE
)
.addComponent(eightCharInstructionLabel)
)
.addGap(7, 7, 7)
)
);
pack();
} // </editor-fold>//GEN-END:initComponents
101
private void passwordField2KeyReleased(java.awt.event.KeyEvent evt)
{ //GEN-FIRST:event_passwordField2KeyReleased //GEN-
HEADEREND:event_passwordField2KeyReleased
if (verifyPasswords()) {
proceedButton.setEnabled(true);
} else {
proceedButton.setEnabled(false);
}
} //GEN-LAST:event_passwordField2KeyReleased
{ //GEN-FIRST:event_passwordField1KeyReleased //GEN-
HEADEREND:event_passwordField1KeyReleased
if (verifyPasswords()) {
proceedButton.setEnabled(true);
} else {
proceedButton.setEnabled(false);
} //GEN-LAST:event_passwordField1KeyReleased
HEADEREND:event_proceedButtonActionPerformed
setVisible(false);
dispose();
102
new EncryptorAndDecryptor(
listOfFilesAndFolders,
"encrypt",
new String(passwordField1.getPassword())
)
.execute();
} //GEN-LAST:event_proceedButtonActionPerformed
/**
*/
PasswordTakerForDecryption.java
package gui;
import core.EncryptorAndDecryptor;
import java.awt.Toolkit;
103
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
this.listOfFilesAndFolders = listOfFilesAndFolders;
try {
for (javax.swing.UIManager.LookAndFeelInfo info :
javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
java.util.logging.Logger
.getLogger(ThankYouDialog.class.getName())
java.util.logging.Logger
.getLogger(ThankYouDialog.class.getName())
.log(java.util.logging.Level.SEVERE, null, ex);
.getLogger(ThankYouDialog.class.getName())
.log(java.util.logging.Level.SEVERE, null, ex);
java.util.logging.Logger
.getLogger(ThankYouDialog.class.getName())
}
//</editor-fold>
initComponents();
setResizable(false);
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
getRootPane().setDefaultButton(proceedButton);
addWindowListener(
new WindowAdapter() {
Toolkit.getDefaultToolkit().beep();
JOptionPane.YES_NO_OPTION
);
if (result == JOptionPane.YES_OPTION)
frame.setDefaultCloseOperation(
105
JFrame.EXIT_ON_CLOSE
);
}
);
}
@SuppressWarnings("unchecked")
suggestionLabel.setFont(
suggestionLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER
);
suggestionLabel.setText(
"Enter the password used to encrypt all the selected encrypted files"
);
passwordField.addKeyListener(
106
new java.awt.event.KeyAdapter() {
}
);
proceedButton.setText("Proceed");
proceedButton.setEnabled(false);
proceedButton.addActionListener(
new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
proceedButtonActionPerformed(evt);
}
}
);
);
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout
.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
javax.swing.GroupLayout.Alignment.TRAILING,
layout
.createSequentialGroup()
107
.addContainerGap()
.addGroup(
layout
.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADI
NG)
.addComponent(
passwordField,
javax.swing.GroupLayout.Alignment.TRAILING
)
.addGroup(
layout
.createSequentialGroup()
.addComponent(jLabel1)
.addGap(0, 0, Short.MAX_VALUE)
)
.addComponent(
suggestionLabel,
javax.swing.GroupLayout.DEFAULT_SIZE,
857,
Short.MAX_VALUE
)
)
.addContainerGap()
)
.addGroup(
javax.swing.GroupLayout.Alignment.TRAILING,
layout
108
.createSequentialGroup()
.addContainerGap(
javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE
)
.addComponent(proceedButton)
)
);
layout.setVerticalGroup(
layout
.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
layout
.createSequentialGroup()
.addContainerGap()
.addComponent(
suggestionLabel,
javax.swing.GroupLayout.PREFERRED_SIZE,
19,
javax.swing.GroupLayout.PREFERRED_SIZE
)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELA
TED)
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELA
TED)
109
18MIS0271 18MIS0393 18MIS0414 VELLORE INSTITUTE OF TECHNOLOGY
.createSequentialGroup()
.addContainerGap(
javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE
)
.addComponent(proceedButton)
)
);
layout.setVerticalGroup(
layout
.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
layout
.createSequentialGroup()
.addContainerGap()
.addComponent(
suggestionLabel,
javax.swing.GroupLayout.PREFERRED_SIZE,
19,
javax.swing.GroupLayout.PREFERRED_SIZE
)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELA
TED)
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELA
TED)
109
.addComponent(
passwordField,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE
)
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED,
javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE
)
.addComponent(
proceedButton,
javax.swing.GroupLayout.PREFERRED_SIZE,
28,
javax.swing.GroupLayout.PREFERRED_SIZE
)
.addContainerGap()
);
pack();
}
private void passwordFieldKeyReleased(java.awt.event.KeyEvent evt)
{ //GEN-FIRST:event_passwordFieldKeyReleased //GEN-
HEADEREND:event_passwordFieldKeyReleased
if (passwordField.getPassword().length > 7) {
proceedButton.setEnabled(true);
110
} else if (passwordField.getPassword().length < 8) {
proceedButton.setEnabled(false);
}
} //GEN-LAST:event_passwordFieldKeyReleased
setVisible(false);
dispose();
new EncryptorAndDecryptor(
listOfFilesAndFolders,
"decrypt",
new String(passwordField.getPassword())
.execute();
} //GEN-LAST:event_proceedButtonActionPerformed
/**
111