Download as pdf or txt
Download as pdf or txt
You are on page 1of 111

FILE ENCRYPTION AND DECRYPTION USING VIGENÈRE CIPHER

AND SHA-512 HASHING ALGORITHM FOR SECURITY


AUTHENTICATION

A PROJECT REPORT

for

INFORMATION AND SECURITY SYSTEMS (CSE3501)

in

M.Tech (Software Engineering)

by

DIVAKAR.M (19MIS0071)

SRI HARSHA (19MIS0080)

KRISHNA CHAITANYA REDDY (19MIS0081)

Under the Guidance of

Prof. BRINDHA K
PROBLEM STATEMENT

Encryption is the process of transforming data into something that appears


random and meaningless (ciphertext). Decryption is the process of turning
ciphertext back into plaintext. File encryption is a method of encrypting data
and transferring files securely for encrypting small or larger amounts of data.
File encryption helps prevent tampering and unauthorized access during file
transfer and storage. In this project, we are using a modified version of the
Vigenère encryption algorithm to encrypt any kind of protected or sensitive
data. A pure implementation of the Vigenère cipher is limited to encrypting only
the text of the alphabet, and the key is of the same form. However, here the file
is encrypted and the key can be any ASCII character (7-bit, 128-character set).

For security verification to decrypt the data we using SHA-512


Hashing algorithm here. During encryption, when the password is entered, its
corresponding hash is created using a hash function. For example, if your
password is "hello" (taking this extremely weak password just for terseness),
then the corresponding hash using SHA-512 hashing algorithm is:

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

Encryption and decryption of any type/format of files using a modified


Vigenère cipher algorithm written in Java language with a graphical user
interface and adopting SHA-512 hash function for password authentication
which stores within the encrypted file. Design the project to encrypt multiple
files at one attempt and decrypt after entering the correct password which
entered at the time of encryption, with effective security advances.

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.

If we want encrypted files to revert to their previous state. Additionally, the


reverse is true. With the encryption password we had previously used, we may
DECRYPT our files and restore them to their original state. Furthermore, the
application doesn't keep a record of our passwords. Instead, it checks the
password using the SHA-512 hashing technique.

LITERATURE SURVEY

1. Performance analysis of encryption algorithms for security


Madhumita Panda

Encryption algorithms play an important role in information security system.


These algorithms enhance the data confidentiality and privacy by making the
information indecipherable. But at the same time, these algorithms consume a
significant amount of computing resources such as CPU time, memory, and
battery power. This paper provides evaluation of both symmetric (AES, DES,
Blowfish) as well as asymmetric (RSA) cryptographic algorithms by taking
different types of files like Binary, text and image files.
2. A novel approach for audio file encryption using hand geometry.
Saja J. Mohammed

The proposed algorithm used a number of hand geometry measurements


properties as keys to encode and decode the audio file, combined with using the
discrete wavelet transform (DWT) and biometric features to increase the
efficiency of the encryption process. They cleared that the retrieved audio signal
has very acceptable loss of its data with certain keeping the main decrypted
message in a good understanding on the receiver side.

3. Encryption and Decryption using Password Based


Encryption, MD5, and DES

Hanna Willa Dhany, Fahmi Izhari, Hasanul Fahmi, Mr Tulus, Mr


Sutarman

Password-based encryption gets the encryption key from the


password. Password-based Encryption is used in the application
because usually the attacker repeatedly tries to guess undetected
keywords and is beyond the original sender / recipient control, if the
keyword is used to log in to the server, it can detect many possibilities
that are not properly done. Password Based Encryption with Message
Digest (MD5) and Data Encryption Standard (DES) is a cryptographic
method that combines hashing and standard encryption methods. MD5
was developed by Ronald Rivest where the MD5 takes messages of any
length and generates a 128-bit message digest, and with the use of DES
working in plaintext it is useful to return the same size ciphertext.

4. Transparent encryption based on network file system filtering


driver

YangLi, Li Yeli and Zheng Liangbin,

This paper introduces the technology of transparent file encryption


based on network file system filtering driver and how it works. The
method can be used for confidential data of network File System
transparent encryption and decryption and ensure the information
security of Network File System. File protected system software based
on file system filter driver is security, efficacious, easy cost, extensible,
maintenance-free and device independent. A method is given based on
the operating system: windows 2000/xp.

5. The Research of Dynamic Encryption & Decryption Methods


Based on the Binary Random Hash

G. Feng, L. Lang, Y. Si and K. Wang

This paper proposes a brand-new technique of encryption and


decryption primarily based totally on circulate cipher. The technique
absolutely deserted the conventional mathematical calculation
technique. Its major precept is to the use of the important thing to get a
binary random Hash mapping; the plaintext may be lightly dispersed in a
recognised binary random Hash, after which mapped to the cipher area
and this encryption technique has a completely sturdy randomness and
collision resistance which the set of rules evaluation suggests that the
time and area complexity of the technique is similar to the conventional
circulate cipher set of rules, each of which might be o ((n)). Finally, we
take a look at the time performance of the technique, and the
experimental effects display that block and multithreading generation will
significantly enhance the encryption performance for big files.

6. Analysis and Detection of Errors In Implementation Of SHA-


512 Algorithms On FPGAs

Ahmad and A. S. Das

In this paper, we gift an in-depth evaluation of the propagation of


mistakes to the output withinside the hardware implementation of SHA-
512. Included on this evaluation are unmarried, temporary in addition to
everlasting faults that can seem at any level of the hash cost
computation. Then advise an mistakes detection scheme primarily based
totally on parity codes and hardware redundancy. file the overall
performance metrics together with area, memory, and throughput for the
implementation of SHA-512 with mistakes detection functionality on an
FPGA of ALTERA. We done 100 insurance withinside the case of
unmarried faults with a place overhead of 21% and with a discounted
throughput of 11.6% with the mistake detection circuit.

7. Nur Algorithm on Data Encryption and Decryption

Nur Aminudin, Andino Maseleno1 , Shankar K2 , S. Hemalatha3 , K.


Sathesh kumar2 , Fauzi1 , Rita Irviani1 , Muhamad Muslihudin

System development (System Development Lifecycle) can mean to


construct a new system to replace old system. In Nur Amin Uddin’s
Encryptor there are two data-reading techniques namely encryption
technique and decryption technique. Encryption technique is built by
applying technique of modern cryptography which holds secrecy on the
symmetric key, so the security of encryption depends only on the key.

8. A Novel Multimedia Encryption and Decryption Technique Using


Binary Tree Traversal

Annu Priya, Keshav Sinha, Manu Priya Darshani & Sudip Kumar
Sahana

In recent years, there is vast improvement in the field of telecommunication and


digital world. While transferring multimedia contents through the
communication channels, the primary concern is the security of the data. To
cope with this problem, there are several traditional and novel encryption
algorithms for protecting the multimedia contents. The multimedia encryption is
well defined in three categories: (i) Complete encryption, Selective encryption,
and combined compression. A novel algorithm is applied using a binary tree
traversal for multi-bit word parallelism using substitution and a two-
dimensional array to perform a nonlinear diffusion process. The result is shown
in term of encryption time, memory usage, and CPU utilization.
9. Enhanced SPK Encryption Algorithm for File Encryption Using Java

T. Subbulakshmi, S. Bhardwai, P. Ranjan and K. A. John

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.

10. A remotely keyed file encryption scheme under mobile cloud


computing

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

• OS: Windows 7/10

• Processor: Intel Core i5

• Memory: 6 GB RAM

SOFTWARE REQUIREMENTS

• NetBeans IDE for JAVA development

• Java jdk minimum of 11.0.1 version

• Gui add-ons plugins

MODULES OF THE PROJECT

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.

ToBeEncryptedOrDecrypted: Action java file which implements from the


user choice to decrypt or encrypt the file.

FileEncryptor: Java executable file to encrypt the file.

FileDecryptor: Java executable file to decrypt the file.

FileChooser: This module initiates the process of selecting any files of user
choice for encryption or decryption.

PasswordTakerForEncryption: A password security to be provided by the file


owner before the encryption process.

PasswordTakerForDecryption: Using hashing algorithm of SHA-512 for


password security authentication to go for the decryption process.

SourceFileNotDeletedDuringEncryption: Checking module, If the selected


file is present or not in the selected location for encryption.
SourceFileNotDeletedDuringDecryption: Checking module, If the selected
file is present or not in the selected location for 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.

Another method for modifying the Vigenere Cipher algorithm, by automatically


changing the cipher key after each encryption step. In this method the key varies
as it is used in the encryption process. The ciphertext will have different
encryption key patterns so the cryptosystem will be more difficult against the
frequency attack.

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:

IDE USED ECLIPSE:

Conclusion and Future Developments

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

D. Y. Sylfania, F. P. Juniawan, L. Laurentinus, and H. A. Pradana, "SMS Security


Improvement using RSA in Complaints Application on Regional Head Election’s Fraud,"
Jurnal Teknologi dan Sistem Komputer, vol. 7, no. 3, pp. 116-120, Jul. 2019.
M. Nazeh, A. Wahid, A. Ali, B. Esparham, and M. Marwan, “A Comparison of Cryptographic
Algorithms : DES , 3DES , AES , RSA and Blowfish for Guessing Attacks Prevention,” J.
Comput. Science Applications and Information Technology, vol. 3, no. 2, pp. 1–7, 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

*/

public class EncryptorAndDecryptor extends SwingWorker<Boolean, Boolean> {


File[] listOfFilesAndFolders;

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;

progressFrame = new EncryptorAndDecryptorProgress(encryptOrDecrypt);


progressFrame.setVisible(true);

fileEncryptorAndDecryptor = new FileEncryptorAndDecryptor();

progressBar = progressFrame.getProgressBar();
progressOfFilesTextField = progressFrame.getProgressOfFilesTextField();

progressPercentLabel = progressFrame.getProgressPercentLabel();

oKButton = progressFrame.getoKButton();
setTotalSizeAndNumberOfAllFiles();

@Override

protected Boolean doInBackground() {

try {
if (encryptOrDecrypt.equalsIgnoreCase("encrypt")) {

encrypt();
} else if (encryptOrDecrypt.equalsIgnoreCase("decrypt")) {

decrypt();
}
} catch (Exception e) {

new ExceptionDialog(
22
"Unexpected System Error!",

"Something hugely badly unexpectadly went awfully wrong",


e

.setVisible(true);
} finally {

return true;

}
}

protected void done() {


try {

progressFrame.setCompletedTask(true);

Toolkit.getDefaultToolkit().beep();
oKButton.setVisible(true);

oKButton.setEnabled(true);

oKButton.setText("OK");
} catch (Exception e) {

new ExceptionDialog(

"Unexpected System Error!",


"Something hugely badly unexpectadly went awfully wrong",

e
)

.setVisible(true);
}
}

23
private void encrypt() {

for (File file : listOfFilesAndFolders) {


encrypt(file);

progressBar.setValue(progressBar.getMaximum());
progressPercentLabel.setText("100%");

private void encrypt(File file) {

if (!file.isDirectory() && file.exists()) {

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[] filesInTheDirectory = file.listFiles();


progressOfFilesTextField.append(
"\n~~~~~~~~~~~~~~~~~~~~ Inside " +

file.getAbsolutePath() +
24
" ~~~~~~~~~~~~~~~~~~~~\n"

);
for (File eachFileInTheDirectory : filesInTheDirectory) {

encrypt(eachFileInTheDirectory);

}
progressOfFilesTextField.append(

"~~~~~~~~~~~~~~~~~~~~ End of " +

file.getAbsolutePath() +
" ~~~~~~~~~~~~~~~~~~~~\n\n"

);

}
}

private void decrypt() {


for (File file : listOfFilesAndFolders) {

decrypt(file);

}
progressBar.setValue(progressBar.getMaximum());

progressPercentLabel.setText("100%");

private void decrypt(File file) {


if (

!file.isDirectory() &&
file.exists() &&
file

.getName()
25
.substring(file.getName().length() - 4, file.getName().length())

.equalsIgnoreCase(".enc")
) {

progressOfFilesTextField.append(

"Decrypting " + file.getAbsolutePath() + "\n"


);

fileEncryptorAndDecryptor.decrypt(

file,
key,

progressBar,

progressPercentLabel,
totalSizeOfAllFiles,

progressOfFilesTextField

);
progressOfFilesTextField.append("Done!\n\n");

} else if (file.isDirectory() && file.exists()) {

File[] filesInTheDirectory = file.listFiles();


progressOfFilesTextField.append(

"\n~~~~~~~~~~~~~~~~~~~~ Inside " +

file.getAbsolutePath() +
" ~~~~~~~~~~~~~~~~~~~~\n"

);
for (File eachFileInTheDirectory : filesInTheDirectory) {

decrypt(eachFileInTheDirectory);
}
progressOfFilesTextField.append(

"~~~~~~~~~~~~~~~~~~~~ End of " +


26
file.getAbsolutePath() +

" ~~~~~~~~~~~~~~~~~~~~\n\n"
);

private void setTotalSizeAndNumberOfAllFiles() {

for (File file : listOfFilesAndFolders) {


setTotalSizeAndNumberOfAllFiles(file);

}
private void setTotalSizeAndNumberOfAllFiles(File file) {

if (!file.isDirectory() && file.exists()) {

totalNumberOfFiles++;
totalSizeOfAllFiles += file.length();

} else if (file.isDirectory() && file.exists()) {

File[] filesInTheDirectory = file.listFiles();

for (File eachFileInTheDirectory : filesInTheDirectory) {

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;

/**
*

* @author Jagadeesh Kowshik Deveshwar

*/
public class FileEncryptorAndDecryptor {

private File destinationFile;

private double accumulator = 0;


boolean areHashesEqual(File file, String keyHash)
throws FileNotFoundException, IOException {

BufferedInputStream fileReader = new BufferedInputStream(


28
new FileInputStream(file.getAbsolutePath())

);
//reading key hash from file

StringBuffer keyHashFromFile = new StringBuffer(128);

for (int i = 0; i < 128; i++) {


keyHashFromFile.append((char) fileReader.read());

//verifying both hashes


System.out.println("keyHashFromFile.to string()= " + keyHashFromFile);

System.out.println("keyHash= " + keyHash);

fileReader.close();
if (keyHashFromFile.toString().equals(keyHash)) {

return true;

}
return false;

private byte[] getHashInBytes(String key) throws NoSuchAlgorithmException


{

byte[] keyHash;

final MessageDigest md = MessageDigest.getInstance("SHA-512");


keyHash = md.digest(key.getBytes());

StringBuilder sb = new StringBuilder();


for (int i = 0; i < keyHash.length; i++) {

sb.append(Integer.toString((keyHash[i] & 0xff) + 0x100,


16).substring(1));
}

String hashOfPassword = sb.toString();


29
System.out.println("hashOfPassword length= " + hashOfPassword.length());

System.out.println("hashOfPassword = " + hashOfPassword);


return hashOfPassword.getBytes();

private String getHashInString(String key) throws NoSuchAlgorithmException


{

byte[] keyHash;

final MessageDigest md = MessageDigest.getInstance("SHA-512");


keyHash = md.digest(key.getBytes());

StringBuilder sb = new StringBuilder();

for (int i = 0; i < keyHash.length; i++) {


sb.append(Integer.toString((keyHash[i] & 0xff) + 0x100,

16).substring(1));

}
String hashOfPassword = sb.toString();

System.out.println("hashOfPassword length= " + hashOfPassword.length());

System.out.println("hashOfPassword = " + hashOfPassword);


return hashOfPassword;

public void encrypt(


File file,

String key,
JProgressBar progressBar,

JLabel progressPercentLabel,
long totalSizeOfAllFiles,
JTextArea progressOfFilesTextField

) {
30
byte[] keyHash;

double percentageOfFileCopied = 0;
if (!file.isDirectory()) {

try {

keyHash = getHashInBytes(key);

destinationFile = new File(file.getAbsolutePath().concat(".enc"));

if (destinationFile.exists()) {
destinationFile.delete();

destinationFile = new File(file.getAbsolutePath().concat(".enc"));

BufferedInputStream fileReader = new BufferedInputStream(

new FileInputStream(file.getAbsolutePath())
);

FileOutputStream fileWriter = new FileOutputStream(

destinationFile,
true

);

//writing key hash to file

fileWriter.write(keyHash, 0, 128);

//encrypting content & writing


byte[] buffer = new byte[262144];
int bufferSize = buffer.length;

int keySize = key.length();


31
progressOfFilesTextField.setText(

progressOfFilesTextField.getText() + " 0%\n"


);

while (fileReader.available() > 0) {

int bytesCopied = fileReader.read(buffer);


for (

int i = 0, keyCounter = 0;

i < bufferSize;
i++, keyCounter %= keySize

) {

buffer[i] += key.toCharArray()[keyCounter];
}

fileWriter.write(buffer, 0, bytesCopied);

long fileLength = file.length();


percentageOfFileCopied += (((double) bytesCopied / fileLength) *

100);

showProgressOnprogressOfFilesTextField(
progressOfFilesTextField,

percentageOfFileCopied,

bytesCopied,
fileLength

);
showProgressOnProgressBarAndProgressPercent(

progressBar,
progressPercentLabel,
bytesCopied,

totalSizeOfAllFiles
32
);

System.out.println("des file length= " +


destinationFile.length());

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!",

"Something hugely badly unexpectadly went awfully wrong",


e
)

.setVisible(true);
33
Logger

.getLogger(FileEncryptorAndDecryptor.class.getName())
.log(Level.SEVERE, null, e);

} catch (SecurityException e) {

new ExceptionDialog(
"File Security Error!!!",

file + " doesn't allow you to do that!",

e
)

.setVisible(true);

} catch (FileNotFoundException e) {
new ExceptionDialog("File Not Found!!!", file + " not found!", e)

.setVisible(true);

} catch (IOException e) {
new ExceptionDialog(

"Can Not Read or Write file!!!",

file + " can not be read or written!",


e

.setVisible(true);
} catch (Exception e) {

new ExceptionDialog(
"Unexpected System Error!",

"Something hugely badly unexpectadly went awfully wrong",


e
)

.setVisible(true);
34
}

}
}

public void decrypt(

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)
);

BufferedInputStream fileReader = new BufferedInputStream(


35
new FileInputStream(file.getAbsolutePath())

);
FileOutputStream fileWriter = new

FileOutputStream(destinationFile);

//decrypting content & writing


byte[] buffer = new byte[262144];

int bufferSize = buffer.length;

int keySize = key.length();


progressOfFilesTextField.setText(

progressOfFilesTextField.getText() + " 0%\n"

);
for (int i = 0; i < 128; i++) {

if (fileReader.available() > 0) {

fileReader.read();
}

while (fileReader.available() > 0) {


int bytesCopied = fileReader.read(buffer);

for (

int i = 0, keyCounter = 0;
i < bufferSize;

i++, keyCounter %= keySize


) {

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(

"destination file length= " + destinationFile.length()


);

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);
}

} else if (!areHashesEqual(file, keyHash)) {

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

chance.\nYour Bad Luck ☺\n\n"

);
}

} catch (NoSuchAlgorithmException e) {

new ExceptionDialog(
"NoSuchAlgorithmException!",

"Something hugely badly unexpectadly went awfully wrong",


e

)
.setVisible(true);
Logger

.getLogger(FileEncryptorAndDecryptor.class.getName())
38
.log(Level.SEVERE, null, e);

} catch (SecurityException e) {
new ExceptionDialog(

"File Security Error!!!",

file + " doesn't allow you to do that!",


e

.setVisible(true);
} catch (FileNotFoundException e) {

new ExceptionDialog("File Not Found!!!", file + " not found!", e)

.setVisible(true);
} catch (IOException e) {

new ExceptionDialog(

"Can Not Read or Write file!!!",


file + " can not be read or written!",

)
.setVisible(true);

} catch (Exception e) {

new ExceptionDialog(
"Unexpected System Error!",

"Something hugely badly unexpectadly went awfully wrong",


e

)
.setVisible(true);
}

}
39
}

private void showProgressOnProgressBarAndProgressPercent(

JProgressBar progressBar,

JLabel progressPercent,
int bytesCopied,

long totalSizeOfAllFiles

) {
int previousProgress = progressBar.getValue();

accumulator += ((double) bytesCopied / totalSizeOfAllFiles) * 100;

if (accumulator >= 1) {

int percentage = previousProgress + (int) accumulator;


accumulator = 0;

progressBar.setValue(percentage);
progressPercent.setText(Integer.toString(percentage) + "%");

}
private void showProgressOnprogressOfFilesTextField(

JTextArea progressOfFilesTextField,
double percentageOfFileCopied,

int bytesCopied,
long fileLength
) {

StringBuilder s = new StringBuilder(


40
progressOfFilesTextField

.getText()
.substring(0, progressOfFilesTextField.getText().length() - 5)

);

if (percentageOfFileCopied < 10) {

s.append(" " + Integer.toString((int) percentageOfFileCopied) +

"%\n");
} else if (percentageOfFileCopied < 100) {

s.append(" " + Integer.toString((int) percentageOfFileCopied) +

"%\n");
} else if (percentageOfFileCopied >= 100) {

s.append(Integer.toString((int) percentageOfFileCopied) + "%\n");

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

* @author Jagadeesh Himayan

*/
public class Main extends javax.swing.JFrame {

public Main(boolean usedTheApplication) {


initComponents();

setResizable(false);

setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);

addWindowListener(
new WindowAdapter() {

public void windowClosing(WindowEvent e) {

JFrame frame = (JFrame) e.getSource();


Toolkit.getDefaultToolkit().beep();

int result = JOptionPane.showConfirmDialog(

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

private void initComponents() {


heading = new javax.swing.JLabel();

jLabel1 = new javax.swing.JLabel();


encryptButton = new javax.swing.JButton();

decryptButton = new javax.swing.JButton();


jLabel4 = new javax.swing.JLabel();
jLabel9 = new javax.swing.JLabel();

jLabel10 = new javax.swing.JLabel();


43
jLabel11 = new javax.swing.JLabel();

jLabel12 = new javax.swing.JLabel();


jLabel13 = new javax.swing.JLabel();

jLabel14 = new javax.swing.JLabel();

jLabel15 = new javax.swing.JLabel();


jLabel16 = new javax.swing.JLabel();

jLabel17 = new javax.swing.JLabel();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

setBackground(new java.awt.Color(0, 0, 0));

heading.setFont(new java.awt.Font("Vrinda", 1, 18)); // NOI18N

heading.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);

heading.setText(
"Welcome to File Encryption & Decryption Software (ISSA Project)"

);

jLabel1.setFont(new java.awt.Font("Forte", 0, 24)); // NOI18N

jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);

jLabel1.setText("I want to");

encryptButton.setFont(new java.awt.Font("Vrinda", 1, 14)); // NOI18N


encryptButton.setText("Encrypt My Files");

encryptButton.addActionListener(
new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {

encryptButtonActionPerformed(evt);
44
}

}
);

decryptButton.setFont(new java.awt.Font("Vrinda", 1, 14)); // NOI18N


decryptButton.setText("Decrypt My Files");

decryptButton.addActionListener(

new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {

decryptButtonActionPerformed(evt);

}
}

);

jLabel4.setFont(new java.awt.Font("Segoe UI Variable", 1, 24)); //

NOI18N

jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
jLabel4.setText("About!");

jLabel9.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N


jLabel9.setText(

"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.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N

jLabel10.setText(
45
"Just click \"YES\" then this software is definitely encrypt any kind

of files for you. If \"Encrypt My Files\""


);

jLabel11.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N


jLabel11.setText(

"encrypts them with the password you enter and thus makes them

unreadable. This way, files such as movies,"


);

jLabel12.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N


jLabel12.setText(

"music, pdf, documents, images, etc. won't open. Executable files

will not be in a state to be executed. The"


);

jLabel13.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N


jLabel13.setText(

"rendered files will have \".enc\" extension after ENCRYPTION."

);

jLabel14.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N


jLabel14.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);

jLabel14.setText(
"Do you want your encrypted file(s) back in the original form ?"
);

jLabel15.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N


46
jLabel16.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N

jLabel16.setText(
"\"Decrypt My Files\" is the option you should select. It

performs DECRYPTION of the given encrypted files. The"

);
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."

);

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(


getContentPane()

);

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)

.addGap(35, 35, 35)


.addComponent(jLabel10)

.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)

.addGap(41, 41, 41)


.addComponent(

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)

.addGap(26, 26, 26)


.addComponent(

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 fileChooser = new FileChooser("ENCRYPT");

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

/**

* @param args the command line arguments

*/
public static void main(String args[]) {

/* 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());
55
break;

}
}

} catch (ClassNotFoundException ex) {

java.util.logging.Logger
.getLogger(Main.class.getName())

.log(java.util.logging.Level.SEVERE, null, ex);

} catch (InstantiationException ex) {


java.util.logging.Logger

.getLogger(Main.class.getName())

.log(java.util.logging.Level.SEVERE, null, ex);


} catch (IllegalAccessException ex) {

java.util.logging.Logger

.getLogger(Main.class.getName())
.log(java.util.logging.Level.SEVERE, null, ex);

} catch (javax.swing.UnsupportedLookAndFeelException ex) {

java.util.logging.Logger
.getLogger(Main.class.getName())

.log(java.util.logging.Level.SEVERE, null, ex);

}
//</editor-fold>

/* Create and display the form */

java.awt.EventQueue.invokeLater(
new Runnable() {
public void run() {

new Main(false).setVisible(true);
56
}

}
);

// Variables declaration - do not modify//GEN-BEGIN:variables


private javax.swing.JButton decryptButton;

private javax.swing.JButton encryptButton;

private javax.swing.JLabel heading;


private javax.swing.JLabel jLabel1;

private javax.swing.JLabel jLabel10;

private javax.swing.JLabel jLabel11;


private javax.swing.JLabel jLabel12;

private javax.swing.JLabel jLabel13;

private javax.swing.JLabel jLabel14;


private javax.swing.JLabel jLabel15;

private javax.swing.JLabel jLabel16;

private javax.swing.JLabel jLabel17;


private javax.swing.JLabel jLabel4;

private javax.swing.JLabel jLabel9;

// End of variables declaration//GEN-END:variables


}

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

*/

public class EncryptorAndDecryptorProgress extends javax.swing.JFrame {

private String encryptOrDecrypt;

private boolean completedTask;

public void setCompletedTask(boolean completedTask) {

this.completedTask = completedTask;
}

public EncryptorAndDecryptorProgress(String encryptOrDecrypt) {

this.encryptOrDecrypt = encryptOrDecrypt;
/* Set the Nimbus look and feel */

//<editor-fold defaultstate="collapsed" desc=" Look and feel setting


code (optional) ">

/* If Nimbus (introduced in Java SE 6) is not available, stay with the


default look and feel.
* For details see

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;

}
}

} catch (ClassNotFoundException ex) {

java.util.logging.Logger
.getLogger(EncryptorAndDecryptorProgress.class.getName())

.log(java.util.logging.Level.SEVERE, null, ex);

} catch (InstantiationException ex) {


java.util.logging.Logger

.getLogger(EncryptorAndDecryptorProgress.class.getName())

.log(java.util.logging.Level.SEVERE, null, ex);


} catch (IllegalAccessException ex) {

java.util.logging.Logger

.getLogger(EncryptorAndDecryptorProgress.class.getName())
.log(java.util.logging.Level.SEVERE, null, ex);

} catch (javax.swing.UnsupportedLookAndFeelException ex) {


java.util.logging.Logger

.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() {

public void windowClosing(WindowEvent e) {


JFrame frame = (JFrame) e.getSource();

int result;

if (completedTask) {
Toolkit.getDefaultToolkit().beep();

result =

JOptionPane.showConfirmDialog(
frame,

"Are you sure you want to exit the application?",

"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,

"Encryption is in progress. " +

"Are you sure you want to exit the application?",


"Exit Application",

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,

"Decryption is in progress. " +


"Are you sure you want to exit the application?",

"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);
}

public JButton getoKButton() {


return oKButton;

public JProgressBar getProgressBar() {

return progressBar;

public JTextArea getProgressOfFilesTextField() {

return progressOfFilesTextField;
}

public JLabel getProgressPercentLabel() {

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

* regenerated by the Form Editor.

*/
@SuppressWarnings("unchecked")

// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-

BEGIN:initComponents
private void initComponents() {

heading = new javax.swing.JLabel();

jScrollPane1 = new javax.swing.JScrollPane();


progressOfFilesTextField = new javax.swing.JTextArea();

progressBar = new javax.swing.JProgressBar();

progressPercentLabel = new javax.swing.JLabel();


oKButton = new javax.swing.JButton();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

heading.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N


progressOfFilesTextField.setColumns(20);

progressOfFilesTextField.setRows(5);

progressOfFilesTextField.setToolTipText("OK");
jScrollPane1.setViewportView(progressOfFilesTextField);

progressPercentLabel.setFont(new java.awt.Font("Tahoma", 1, 14)); //


NOI18N

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);

}
}

);

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(


getContentPane()

);

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
)
)

.addGap(11, 11, 11)


67
)

);
pack();

} // </editor-fold>//GEN-END:initComponents

private void oKButtonActionPerformed(java.awt.event.ActionEvent evt)

{ //GEN-FIRST:event_oKButtonActionPerformed //GEN-

HEADEREND:event_oKButtonActionPerformed
new Main(true).setVisible(true);

setVisible(false);

dispose();
} //GEN-LAST:event_oKButtonActionPerformed

// Variables declaration - do not modify//GEN-BEGIN:variables

private javax.swing.JLabel heading;


private javax.swing.JScrollPane jScrollPane1;

private javax.swing.JButton oKButton;

private javax.swing.JProgressBar progressBar;


private javax.swing.JTextArea progressOfFilesTextField;

private javax.swing.JLabel progressPercentLabel;

// End of variables declaration//GEN-END:variables


}

FileChooser.java
package gui;

import static javax.swing.JFileChooser.FILES_AND_DIRECTORIES;

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;

/**
*

* @author Jagadeesh Kowshik Deveshwar

*/
public class FileChooser extends javax.swing.JFrame {

/**

* Creates new form FileChooser


*/

private File[] listOfFilesAndFolders;

private String encryptOrDecrypt;


boolean addingNewFilesToExisting;

public FileChooser(String encryptOrDecrypt) {

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);

} catch (InstantiationException ex) {

java.util.logging.Logger
.getLogger(FileChooser.class.getName())

.log(java.util.logging.Level.SEVERE, null, ex);

} catch (IllegalAccessException ex) {


java.util.logging.Logger

.getLogger(FileChooser.class.getName())

.log(java.util.logging.Level.SEVERE, null, ex);


} catch (javax.swing.UnsupportedLookAndFeelException ex) {

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"

);

UIManager.put("FileChooser.openButtonText", "Select Files To


Encrypt");

} else if (encryptOrDecrypt.equalsIgnoreCase("decrypt")) {

UIManager.put(
"FileChooser.openDialogTitleText",

"Select Files To Decrypt"

);
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() {

public void windowClosing(WindowEvent e) {

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;
}

} catch (ClassNotFoundException ex) {


java.util.logging.Logger

.getLogger(FileChooser.class.getName())

.log(java.util.logging.Level.SEVERE, null, ex);


} catch (InstantiationException ex) {

java.util.logging.Logger

.getLogger(FileChooser.class.getName())
.log(java.util.logging.Level.SEVERE, null, ex);

} catch (IllegalAccessException ex) {

java.util.logging.Logger
.getLogger(FileChooser.class.getName())

.log(java.util.logging.Level.SEVERE, null, ex);

} catch (javax.swing.UnsupportedLookAndFeelException ex) {


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(

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",

"Select Files To Encrypt"

);
UIManager.put("FileChooser.openButtonText", "Select Files To

Encrypt");

} else if (encryptOrDecrypt.equalsIgnoreCase("decrypt")) {
UIManager.put(

"FileChooser.openDialogTitleText",

"Select Files To Decrypt"


);

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");
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() {

public void windowClosing(WindowEvent e) {


setVisible(false);

dispose();

new Main(false).setVisible(true);
}

);
}

private boolean anyEncFileExists(File[] listOfFilesAndFolders) {


for (File file : listOfFilesAndFolders) {

String filePath = file.getAbsoluteFile().toString();


if (
!file.isDirectory() &&

filePath
75
.substring(filePath.length() - 4, filePath.length())

.equals(".enc")
) {

System.out.println(file.getAbsoluteFile() + " is already

encrypted");
Toolkit.getDefaultToolkit().beep();

JOptionPane.showMessageDialog(

null,
"1 or more files are already encrypted !! \nPlease de-select

them."

);
return true;

}
return false;

private boolean allAreEncFiles(File[] listOfFilesAndFolders) {

for (File file : listOfFilesAndFolders) {

String filePath = file.getAbsoluteFile().toString();


if (

!file.isDirectory() &&
!filePath

.substring(filePath.length() - 4, filePath.length())
.equals(".enc")
) {

System.out.println(file.getAbsoluteFile() + " is not encrypted");


76
Toolkit.getDefaultToolkit().beep();

JOptionPane.showMessageDialog(
null,

"1 or more files are not encrypted !! \nPlease de-select them."

);
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

private void initComponents() {


jFileChooser1 = new javax.swing.JFileChooser();

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

// Variables declaration - do not modify//GEN-BEGIN:variables

private javax.swing.JFileChooser jFileChooser1;


// End of variables declaration//GEN-END:variables

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 {

private File[] listOfFilesAndFolders;


private String encryptOrDecrypt;

81
public ToBeEncryptedOrDecrypted(

File[] listOfFilesAndFolders,
String encryptOrDecrypt

) {

this.listOfFilesAndFolders = listOfFilesAndFolders;
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;

}
}

} catch (ClassNotFoundException ex) {

java.util.logging.Logger
.getLogger(ToBeEncryptedOrDecrypted.class.getName())

.log(java.util.logging.Level.SEVERE, null, ex);

} catch (InstantiationException ex) {


java.util.logging.Logger

.getLogger(ToBeEncryptedOrDecrypted.class.getName())
.log(java.util.logging.Level.SEVERE, null, ex);

} catch (IllegalAccessException ex) {


java.util.logging.Logger
.getLogger(ToBeEncryptedOrDecrypted.class.getName())

.log(java.util.logging.Level.SEVERE, null, ex);


82
} catch (javax.swing.UnsupportedLookAndFeelException ex) {

java.util.logging.Logger
.getLogger(ToBeEncryptedOrDecrypted.class.getName())

.log(java.util.logging.Level.SEVERE, null, ex);

}
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) {

JFrame frame = (JFrame) e.getSource();


Toolkit.getDefaultToolkit().beep();

int result = JOptionPane.showConfirmDialog(


frame,
"Are you sure you want to exit the application?",

"Exit Application",
83
JOptionPane.YES_NO_OPTION

);
if (result == JOptionPane.YES_OPTION)

frame.setDefaultCloseOperation(

JFrame.EXIT_ON_CLOSE
);

}
);

displayListOfFilesInTheTextField();
getRootPane().setDefaultButton(encryptOrDecryptButton);

private void displayListOfFilesInTheTextField() {


for (Integer i = 0, j = 1; i < listOfFilesAndFolders.length; i++, j++) {

listOfFilesAndFoldersTextField.append(

j.toString() + ". " + listOfFilesAndFolders[i].getName() + "\n"


);

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

* regenerated by the Form Editor.

*/
@SuppressWarnings("unchecked")

// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-

BEGIN:initComponents
private void initComponents() {

heading = new javax.swing.JLabel();

jScrollPane1 = new javax.swing.JScrollPane();


listOfFilesAndFoldersTextField = new javax.swing.JTextArea();

reSelectFilesButton = new javax.swing.JButton();

addMoreFilesButton = new javax.swing.JButton();


encryptOrDecryptButton = new javax.swing.JButton();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

heading.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N

heading.setText("List of files/folders to be encrypted:");

listOfFilesAndFoldersTextField.setColumns(20);

listOfFilesAndFoldersTextField.setRows(5);
jScrollPane1.setViewportView(listOfFilesAndFoldersTextField);

reSelectFilesButton.setText("Forget This List & Re-Select Files");

reSelectFilesButton.addActionListener(
new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {

reSelectFilesButtonActionPerformed(evt);
85
VELLORE INSTITUTE OF TECHNOLOGY

}
);

addMoreFilesButton.setText("Add More Files To Existing");

addMoreFilesButton.addActionListener(
new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

addMoreFilesButtonActionPerformed(evt);
}

);

encryptOrDecryptButton.setFont(new java.awt.Font("AR JULIAN", 1, 24));

// NOI18N
encryptOrDecryptButton.addActionListener(

new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {


encryptOrDecryptButtonActionPerformed(evt);

}
);

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(


getContentPane()

);
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

.addGap(92, 92, 92)


.addComponent(reSelectFilesButton)

)
.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

private void reSelectFilesButtonActionPerformed(


90
VELLORE INSTITUTE OF TECHNOLOGY

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

// Variables declaration - do not modify//GEN-BEGIN:variables

private javax.swing.JButton addMoreFilesButton;

private javax.swing.JButton encryptOrDecryptButton;


private javax.swing.JLabel heading;

private javax.swing.JScrollPane jScrollPane1;

private javax.swing.JTextArea listOfFilesAndFoldersTextField;


private javax.swing.JButton reSelectFilesButton;

// End of variables declaration//GEN-END:variables

}
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

public class PasswordTakerForEncryption extends javax.swing.JFrame {

private File[] listOfFilesAndFolders;


public PasswordTakerForEncryption(File[] listOfFilesAndFolders) {

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;

}
}

} catch (ClassNotFoundException ex) {

java.util.logging.Logger
.getLogger(ToBeEncryptedOrDecrypted.class.getName())

.log(java.util.logging.Level.SEVERE, null, ex);

} catch (InstantiationException ex) {


java.util.logging.Logger

.getLogger(ToBeEncryptedOrDecrypted.class.getName())

.log(java.util.logging.Level.SEVERE, null, ex);


} catch (IllegalAccessException ex) {

java.util.logging.Logger
.getLogger(ToBeEncryptedOrDecrypted.class.getName())

.log(java.util.logging.Level.SEVERE, null, ex);


} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger

.getLogger(ToBeEncryptedOrDecrypted.class.getName())
92
VELLORE INSTITUTE OF TECHNOLOGY

.log(java.util.logging.Level.SEVERE, null, ex);

}
initComponents();

setResizable(false);

eightCharInstructionLabel.setVisible(false);
setLocationRelativeTo(null);

setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);

getRootPane().setDefaultButton(proceedButton);
addWindowListener(

new WindowAdapter() {

public void windowClosing(WindowEvent e) {


JFrame frame = (JFrame) e.getSource();

Toolkit.getDefaultToolkit().beep();

int result = JOptionPane.showConfirmDialog(


frame,

"Are you sure you want to exit the application?",

"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();

char password2[] = passwordField2.getPassword();

if (password1.length < 8) {
eightCharInstructionLabel.setText(

"For security reasons you must enter password of atleast 8

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

// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-

BEGIN:initComponents
private void initComponents() {

jLabel1 = new javax.swing.JLabel();

passwordField1 = new javax.swing.JPasswordField();


jLabel2 = new javax.swing.JLabel();

passwordField2 = new javax.swing.JPasswordField();

proceedButton = new javax.swing.JButton();


suggestionLabel = new javax.swing.JLabel();

eightCharInstructionLabel = new javax.swing.JLabel();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

jLabel1.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N


jLabel1.setText("Enter a password:");

passwordField1.addKeyListener(
new java.awt.event.KeyAdapter() {

public void keyReleased(java.awt.event.KeyEvent evt) {

passwordField1KeyReleased(evt);
}

}
);

jLabel2.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N


jLabel2.setText("Re-enter the password:");

95
VELLORE INSTITUTE OF TECHNOLOGY

passwordField2.setToolTipText("");

passwordField2.addKeyListener(
new java.awt.event.KeyAdapter() {

public void keyReleased(java.awt.event.KeyEvent evt) {

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() {

public void actionPerformed(java.awt.event.ActionEvent evt) {


proceedButtonActionPerformed(evt);

}
);

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.setForeground(new java.awt.Color(255, 0, 0));


eightCharInstructionLabel.setText(

"For security reasons you must enter password of atleast 8 characters"

);
eightCharInstructionLabel.setFocusable(false);

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(


getContentPane()

);

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

private void passwordField1KeyReleased(java.awt.event.KeyEvent evt)

{ //GEN-FIRST:event_passwordField1KeyReleased //GEN-

HEADEREND:event_passwordField1KeyReleased
if (verifyPasswords()) {

proceedButton.setEnabled(true);

} else {
proceedButton.setEnabled(false);

} //GEN-LAST:event_passwordField1KeyReleased

private void proceedButtonActionPerformed(java.awt.event.ActionEvent evt)


{ //GEN-FIRST:event_proceedButtonActionPerformed //GEN-

HEADEREND:event_proceedButtonActionPerformed
setVisible(false);
dispose();

102
new EncryptorAndDecryptor(

listOfFilesAndFolders,
"encrypt",

new String(passwordField1.getPassword())

)
.execute();

} //GEN-LAST:event_proceedButtonActionPerformed

/**

* @param args the command line arguments

*/

// Variables declaration - do not modify//GEN-BEGIN:variables

private javax.swing.JLabel eightCharInstructionLabel;


private javax.swing.JLabel jLabel1;

private javax.swing.JLabel jLabel2;

private javax.swing.JPasswordField passwordField1;


private javax.swing.JPasswordField passwordField2;

private javax.swing.JButton proceedButton;

private javax.swing.JLabel suggestionLabel;


// End of variables declaration//GEN-END:variables

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;

public class PasswordTakerForDecryption extends javax.swing.JFrame

private File[] listOfFilesAndFolders;


public PasswordTakerForDecryption(File[] listOfFilesAndFolders) {

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;

}
}

} catch (ClassNotFoundException ex) {

java.util.logging.Logger
.getLogger(ThankYouDialog.class.getName())

.log(java.util.logging.Level.SEVERE, null, ex);


} catch (InstantiationException ex) {

java.util.logging.Logger
.getLogger(ThankYouDialog.class.getName())
.log(java.util.logging.Level.SEVERE, null, ex);

} catch (IllegalAccessException ex) {


104
java.util.logging.Logger

.getLogger(ThankYouDialog.class.getName())
.log(java.util.logging.Level.SEVERE, null, ex);

} catch (javax.swing.UnsupportedLookAndFeelException ex) {

java.util.logging.Logger
.getLogger(ThankYouDialog.class.getName())

.log(java.util.logging.Level.SEVERE, null, ex);

}
//</editor-fold>

initComponents();

setResizable(false);
setLocationRelativeTo(null);

setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);

getRootPane().setDefaultButton(proceedButton);
addWindowListener(

new WindowAdapter() {

public void windowClosing(WindowEvent e) {


JFrame frame = (JFrame) e.getSource();

Toolkit.getDefaultToolkit().beep();

int result = JOptionPane.showConfirmDialog(


frame,

"Are you sure you want to exit the application?",


"Exit Application",

JOptionPane.YES_NO_OPTION
);
if (result == JOptionPane.YES_OPTION)

frame.setDefaultCloseOperation(
105
JFrame.EXIT_ON_CLOSE

);
}

);
}

@SuppressWarnings("unchecked")

// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-


BEGIN:initComponents

private void initComponents() {

suggestionLabel = new javax.swing.JLabel();


jLabel1 = new javax.swing.JLabel();

passwordField = new javax.swing.JPasswordField();

proceedButton = new javax.swing.JButton();


setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

suggestionLabel.setFont(

new java.awt.Font("Source Code Pro Semibold", 1, 15)


); // NOI18N

suggestionLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER

);
suggestionLabel.setText(

"Enter the password used to encrypt all the selected encrypted files"
);

jLabel1.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N


jLabel1.setText("Enter the password:");
passwordField.setToolTipText("");

passwordField.addKeyListener(
106
new java.awt.event.KeyAdapter() {

public void keyReleased(java.awt.event.KeyEvent evt) {


passwordFieldKeyReleased(evt);

}
);

proceedButton.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N

proceedButton.setText("Proceed");
proceedButton.setEnabled(false);

proceedButton.addActionListener(

new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {

proceedButtonActionPerformed(evt);

}
}

);

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(


getContentPane()

);

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)

.addGap(398, 398, 398)

)
);

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)

.addGap(398, 398, 398)

)
);

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

private void proceedButtonActionPerformed(java.awt.event.ActionEvent evt)


{

setVisible(false);

dispose();
new EncryptorAndDecryptor(

listOfFilesAndFolders,

"decrypt",
new String(passwordField.getPassword())

.execute();
} //GEN-LAST:event_proceedButtonActionPerformed

/**

* @param args the command line arguments


*/

// Variables declaration - do not modify//GEN-BEGIN:variables

private javax.swing.JLabel jLabel1;


private javax.swing.JPasswordField passwordField;

private javax.swing.JButton proceedButton;


private javax.swing.JLabel suggestionLabel;

// End of variables declaration//GEN-END:variables


}

111

You might also like