This document provides an overview and implementation details of an image and text encryption/decryption project using RSA encryption. It includes chapters on introduction/background, hardware/software specifications, feasibility study, preliminary design including ER diagram and data flow diagram, screen layouts, testing approach including white and black box testing, and implementation details of the modules. The implementation utilizes Java and generates RSA public/private key pairs to encrypt and decrypt text and images.
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Image and text Encryption using RSA algorithm in java
1. A
PROJECT REPORT ON
“Image and Text Encryption and Decryption”
In the fulfillment of theRequirement for the Degree of
BachelorofComputerApplication(B.C.A.)
Submitted By
Mr. PATIL PIYUSH ANIL
To
G. H. Raisoni Institute of Business Management, Jalgaon
Affiliated To
Kavayitri Bahinabai Chaudhari, North
Maharashtra University, Jalgaon
2019-2020
2. ACKNOWLEDGEMENT
A successful project is the result of a good team- work
whichconsistsofnotonlythepartnerswhoputin their long
and hard work but also those who guided them. Indeed, a
truesaying.
I would like to thanks to ______ and Hon. _________and
our Project guide “_______” all my college Faculty
members for providing me with valuable support and guiding
me throughout my college days.
Thanks andRegards
Mr. PATIL PIYUSH ANIL
3. Index
Chapter Sr. No Topic Pages
1 Introduction
1.1 Introduction to Project 1
1.2 Introduction to Project Existing System and Need for
New System
1-2
1.3 PROBLEM STATEMENT 2
1.4 OBJECTIVE 3
2 Project Details
2.1 Hardware/ Software Specification 4
3 Feasibility study
3.1 What is feasibility? 5
3.2 Technical feasibility 5
3.3 Economic feasibility 5
3.4 Operational feasibility 6
4 Preliminary Design
4.1 Introduction 7
4.2 Preliminary Design 7
4.3 Entity Relationship Diagram 10
4.4 Data Flow Diagram 11
5 Screen Layout 14
6 Testing
7.1 Introduction 18
7.2 White Box Testing 19
7.3 Black Box Testing 20
7 Implementation 22
8 Future Enhancement 31
9 Conclusion 32
10 Bibliography 33
4. Page | 1
Chapter 1
Introduction to project
Encryption software has become important when it comes to protecting your
Data. Hack attempts and privacy intrusions mean that it's become easier than ever
for complete strangers to access your most personal details stored on your computer.
For businesses its worse, as the exposure of sensitive or confidential records can
result in financial losses as well as heavy fines.
While there are a number of security solutions available, everything from free
anti-malware tools for home consumers and cloud anti-virus for business, even
simple human error can undermine these attempts to secure data.
Encryption software is already deployed by some large corporations and
government agencies to protect data, but it's also available and now accessible for a
wider range of users.
Once properly setup, even if your security software fails,
thieves/hackers/snoopers would still find it almost impossible to do anything with
any encrypted data that might be exposed.
1.1Existing System:-
There may exist many applications of encryption and decryption of varies type
of file formats .this software are paid software and mainly available as web
applications so they required high speed internet connection.
5. Page | 2
New System:-
The proposed system suggest a new concept that is free desktop application.
It means user can use this application free of cost .whale in existed system user has
to pay some amount to use the services.
The new system will work in offline mode. Manse user can use it any time
without any problem. The proposed system uses RSA (Rivest–Shamir–Adleman)
algorithm. RSA is known to be the strongest publicly available encryption method.
This algorithm works with both private key and public key. The only way of
decrypting the files which are encrypted with the public key is to use the private key.
Users’ file will be encrypted and saved to desktop .Then, user has to enter the private
key to decrypt the file.
The proposed study is enriched with Waterfall Development Methodology
which implements a sequential based stage by stage concept.
1.2. PROBLEM STATEMENT:-
The underlying respective architecture of most IT systems, including the
desktop computer and internet, does not guarantee security. Users with malicious
intents have always found a way of exploiting one vulnerability or the other. An
attack that affects the confidentiality of information often presents the platform for
the integrity of such information to be compromised. Intercepted information on
transit would make little or no sense to an interceptor if he is not able to decipher the
content of the information. This explains why it is very necessary to ensure
that even when an intruder or unauthorized user successfully obtains access to
some information the confidentiality and integrity of the information remain
uncompromised.
6. Page | 3
1.3. OBJECTIVE:-
The objective of this project is to design and implement an application that
encrypts and decrypts plain text and images using R.S.A algorithm. EXISTING
SYSTEM Designing an encryption/decryption system, amongst other things,
requires decision on the basic functionality of the software, and the choice of
cryptographic algorithm to be used. While the functionality supports the
attractiveness of the system, the type of cryptographic algorithm actually determines
how much security the system would actually provide. Hence, this forms the major
component in the system design
7. Page | 4
Chapter 2
Hardware/Software Details
Hardware/Software Hardware/Software
Element
Specification/version
Hardware Processor Intel core to duo
RAM 4 GB
Hard Disk 100 GB
Software OS Windows
Java and Net beans IDE
8. Page | 5
Chapter 3
Feasibility Study
3.1 What is Feasibility:-
A feasibility study is an analysis that takes all of a project's relevant factors
into account—including economic, technical, legal, and scheduling considerations
to ascertain the likelihood of completing the project successfully. Project managers
use feasibility studies to discern the pros and cons of undertaking a project before
they invest a lot of time and money into it.
3.2Technical Feasibility:-
It is always essential to evaluate the various aspects before
we develop a system. Evaluation should always justify the cost and
benefits ratio. If it is found that benefits are less compare to the cost of
project, thenitisbettertoavoidgoinginforcomputerization. So technical
feasibility is analysed. It has taken 2 days.
9. Page | 6
3.3Operational Feasibility:-
If you plan to change something inside the company that will affect how
the organization runs or when a client asks you to explore a new product or
process that will affect elements within their own organization. So, it has taken
2 days.
10. Page | 7
Chapter 4
Preliminary Design
4.1 Introduction:-
About RSA
RSA is an encryption algorithm.
Developed in: 1977.
Developed by: Ron Rivest, Adi Shamir, and Leonard Adleman.
The RSA algorithm is the most commonly used public key encryption algorithm.
Encryption and Decryption
Public Key Encryption:-
It is also known as asymmetric cryptography.
11. Page | 8
Two keys are used: Public Key and Private Key.
Public Key: For encryption.
Private Key: For decryption, also known as a secret key.
Public Key: Shared with the public that wants to send us data.
Private Key: Kept secret so that when someone sends us data encrypted by our
Public Key, we can decrypt the data using the Private Key.
HOW RSA WORKS:-
Both users (sender and receiver) generates a public and private key.
Flowchart of Generation of Public and Private Key in RSA.
12. Page | 9
After getting the public and private key the main thing isto encrypt and decrypt File
using RSA.
Text Encryption and Decryption in RSA:-
RSA Algorithm:-
The public and the private key-generation algorithm is the most complex part
of RSA cryptography. Two large prime numbers, p and q, are generated. A modulus
n is calculated by multiplying p and q. This number is used by both the public and
private keys and provides the link between them. The public key consists of the
modulus n, and a public exponent, e as it's a prime number that is not too large. The
e figure doesn’t have to be a secretly selected prime number as the public key is
shared with everyone. The private key consists of the modulus n and the private
exponent d, which is calculated using the Extended Euclidean algorithm to find the
multiplicative inverse with respect to the totient of n.
RSA algorithm is an asymmetric cryptography algorithm. Asymmetric means
that it works on two different keys i.e. Public Key and Private Key. As the name
suggests that the Public Key is given to everyone and Private Key is kept private.
14. Page | 11
4.4 Flow Chart for Encryption and Decryption:-
The above flow chart shows how the project in this article works. The flow
chart explains in a step by step manner the processing of the encryption and
decryption, using JAVA. In this project, we only consider the images not audio.
Images are encrypted, and create the *.txt file, the same file is used for decryption.
IMAGE CRYPTOGRAPHY METHODOLOGY BY RSA:-
The RSA is an cryptographic algorithm which is use to encrypt and decrypt
the data. This algorithm developed in 1977 by Ron Rivest, Adi Shamir, and Leonard
Adleman. RSA cryptosystem is also known as the public-key cryptosystems. RSA
is normally used for secure data transmission.
The encryption is starting on the RSA algorithm with the selection of two
large prime numbers, along with an auxiliary value, as the public key. The prime
numbers are keep in secret. The public key is used to encrypt a message, and private
key is used to decrypt a message or information. The RSA algorithm is encrypt the
original image and decrypts the image by the different keys
15. Page | 12
RSA is an algorithm is using in the modern computer environment to encrypt
and decrypt the data in transform. The RSA algorithm is also called as an asymmetric
cryptographic algorithm. Asymmetric cryptosystem means two different keys are
using in the encryption and decryption. In the two keys one key is using for
encryption and the second key is using for decryption. This RSA algorithm is also
called as the public key cryptography. Because one of the secret key can be given to
everyone which means public. The other key must be kept private.
17. Page | 14
Chapter 5
Screen Layout
After Starting application we can see the home page
After Click on Get Started Button Next window is open where there are
two options
18. Page | 15
Here User will select text or images
After User will Select text or Image for Safety application
Ask Password
19. Page | 16
On text Selection user Will navigate to for text Encryption
On Image Selection user Will navigate to for Image Encryption
Here are two options one for image encryption and other for image
decryption
20. Page | 17
After Encryption
In this image we can see there is a button to select image. After
encryption image will be automatically saved to Desktop
After decryption
In this image user will select the encrypted image and will get decrypted
image as output. Decrypted image will automatically save to Desktop
21. Page | 18
Chapter 6
Testing
6.1 Introduction:-
Software Testing is a method to check whether the actual software product
matches expected requirements and to ensure that software product is Defect free. It
involves execution of software/system components using manual or automated tools
to evaluate one or more properties of interest. The purpose of software testing is to
identify errors, gaps or missing requirements in contrast to actual requirements.
Why Software Testing is Important?
Software Testing is Important because if there are any bugs or errors in the
software, it can be identified early and can be solved before delivery of the software
product. Properly tested software product ensures reliability, security and high
performance which further results in time saving, cost effectiveness and customer
satisfaction.
What are the benefits of Software Testing?
Here are the benefits of using software testing:-
Cost-Effective: It is one of the important advantages of software testing.
Testing any IT project on time helps you to save your money for the long term. In
case if the bugs caught in the earlier stage of software testing, it costs less to fix.
Security: It is the most vulnerable and sensitive benefit of software testing.
People are looking for trusted products. It helps in removing risks and problems
earlier.
Product quality: It is an essential requirement of any software product. Testing
ensures a quality product is delivered to customers.
22. Page | 19
Customer Satisfaction: The main aim of any product is to give satisfaction to
their customers. UI/UX Testing ensures the best user experience.
6.2White Box Testing
White Box Testing is software testing technique in which internal structure,
design and coding of software are tested to verify flow of input-output and to
improve design, usability and security. In white box testing, code is visible to testers
so it is also called Clear box testing, Open box testing, Transparent box testing,
Code-based testing and Glass box testing.
Advantages of White Box Testing:-
Code optimization by finding hidden errors.
White box tests cases can be easily automated.
Testing is more thorough as all code paths are usually covered.
Testing can start early in SDLC even if GUI is not available.
23. Page | 20
Disadvantages of White Box Testing:-
White box testing can be quite complex and expensive.
Developers who usually execute white box test cases detest it. The
white box testing by developers is not detailed can lead to production
errors.
White box testing requires professional resources, with a detailed
understanding of programming and implementation.
White-box testing is time-consuming, bigger programming
applications take the time to test fully.
6.3Black Box Testing:-
Black Box Testing is a software testing method in which the functionalities of
software applications are tested without having knowledge of internal code structure,
implementation details and internal paths. Black Box Testing mainly focuses on
input and output of software applications and it is entirely based on software
requirements and specifications. It is also known as Behavioral Testing.
24. Page | 21
Tools used for Black Box Testing:-
Tools used for Black box testing largely depends on the type of black box
testing you are doing.
For Functional/ Regression Tests you can use - QTP, Selenium
For Non-Functional Tests, you can use - LoadRunner, Jmeter
Black Box Testing and Software Development Life Cycle (SDLC):-
Black box testing has its own life cycle called Software Testing Life Cycle
(STLC) and it is relative to every stage of Software Development Life Cycle of
Software Engineering.
Requirement - This is the initial stage of SDLC and in this stage, a requirement is
gathered. Software testers also take part in this stage.
Test Planning & Analysis - Testing Types applicable to the project are determined.
A Test Plan is created which determines possible project risks and their mitigation.
Design - In this stage Test cases/scripts are created on the basis of software
requirement documents
Test Execution- In this stage Test Cases prepared are executed. Bugs if any are fixed
and re-tested.
25. Page | 22
Chapter 8
Implementation
This project develop in java .it is a windows executable file with extinction
(.jar)
The application divided into three module
First module :- home module (home.java)
Second module :- text module (text.java)
Third module :- image module (image.java)
The image module can be sub-divided as two modules Encryption (encryption.java)
and Decryption (decryption.java) module.
Text EncryptionGenerating RSA Public Private Key:-
(RSAKeyPairGenerator.java):-
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.security.*;
import java.util.Base64;
public class RSAKeyPairGenerator {
private PrivateKey privateKey;
private PublicKey publicKey;
26. Page | 23
public RSAKeyPairGenerator() throws NoSuchAlgorithmException {
KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");
keyGen.initialize(1024);
KeyPair pair = keyGen.generateKeyPair();
this.privateKey = pair.getPrivate();
this.publicKey = pair.getPublic();
}
public void writeToFile(String path, byte[] key) throws IOException {
File f = new File(path);
f.getParentFile().mkdirs();
FileOutputStream fos = new FileOutputStream(f);
fos.write(key);
fos.flush();
fos.close();
}
public PrivateKey getPrivateKey() {
return privateKey;
}
public PublicKey getPublicKey() {
return publicKey;
}
public static void main(String[] args) throws NoSuchAlgorithmException, IOExcepti
on {
RSAKeyPairGenerator keyPairGenerator = new RSAKeyPairGenerator();
keyPairGenerator.writeToFile("RSA/publicKey", keyPairGenerator.getPublicKey()
.getEncoded());
keyPairGenerator.writeToFile("RSA/privateKey", keyPairGenerator.getPrivateKey
().getEncoded());
System.out.println(Base64.getEncoder().encodeToString(keyPairGenerator.getPub
licKey().getEncoded()));
27. Page | 24
System.out.println(Base64.getEncoder().encodeToString(keyPairGenerator.getPri
vateKey().getEncoded()));
}
}
We can use factory method to generate these keys using KeyPairGenerator.
For the demo purpose we are using a key size of 1024. By default, the private key
is generated in PKCS#8 format and the public key is generated in X.509 format.
Once these keys are generated, either you can write these keys in a file and share
the file containing public keys with the client. Remember, the public key is written
in the text file as X.509 format. Also, we can do a base64 encode to make it
readable and share the string with the client.
Text Encryption:-
public static PublicKey getPublicKey(String base64PublicKey){
PublicKey publicKey = null;
try{
X509EncodedKeySpec keySpec = new X509EncodedKeySpec(Base64.getDecoder().d
ecode(base64PublicKey.getBytes()));
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
publicKey = keyFactory.generatePublic(keySpec);
return publicKey;
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (InvalidKeySpecException e) {
e.printStackTrace();
}
return publicKey;
}
We have encryption.java that has methods defined for RSA encryption and
decryption. Let us discuss about encryption first. As we discussed above the public
key generated is in X.509 format and we use public key for encryption. Hence, we
28. Page | 25
need X509EncodedKeySpec class to convert it again to RSA public key.
Remember, that we have base64 encoded public keys. Hence, first let us first
Base64 decode and generate the public key.
we have a simple method encrypt()that takes the string to be encrypted and
the Base64 encoded RSA key for encryption. Here getPublicKey() is the method
that we defined above.
public static byte[] encrypt(String data, String publicKey) throws BadPaddingExceptio
n, IllegalBlockSizeException, InvalidKeyException, NoSuchPaddingException, NoSuchAlgo
rithmException {
Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");
cipher.init(Cipher.ENCRYPT_MODE, getPublicKey(publicKey));
return cipher.doFinal(data.getBytes());
}
Text Decryption:-
public staticPrivateKey getPrivateKey(String base64PrivateKey){
PrivateKey privateKey = null;
PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(Base64.getDecoder().dec
ode(base64PrivateKey.getBytes()));
KeyFactory keyFactory = null;
try {
keyFactory = KeyFactory.getInstance("RSA");
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
try {
privateKey = keyFactory.generatePrivate(keySpec);
} catch (InvalidKeySpecException e) {
e.printStackTrace();
}
return privateKey;
}
For decryption we will be using private key and we discussed above that the
private key is generated in PKCS#8 format. Hence, following is the code to
29. Page | 26
generate the private key from base64 encoded string using
PKCS8EncodedKeySpec.
Now following is the decrypt method that accepts RSA encrypted string and
Base64 encoded RSA private key for decryption.
public static String decrypt(String data, String base64PrivateKey) throws IllegalBloc
kSizeException, InvalidKeyException, BadPaddingException, NoSuchAlgorithmException, N
oSuchPaddingException {
return decrypt(Base64.getDecoder().decode(data.getBytes()), getPrivateKey(bas
e64PrivateKey));
}
Image Encryption:-
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
34. Page | 31
Chapter 8
Future Enhancement
In today’s world the protection of sensitive data is one of the most critical
concerns for organizations and their customers. This, coupled with growing
regulatory pressures, is forcing businesses to protect the integrity, privacy and
security of critical information. As a result cryptography is emerging as the
foundation for enterprise data security and compliance, and quickly becoming the
foundation of security best practice. Cryptography, once seen as a specialized,
esoteric discipline of information security, is finally coming of age.
No one would argue that cryptography and encryption are new technologies.
It was true decades ago and it is still true today – encryption is the most reliable way
to secure data. National security agencies and major financial institutions have long
protected their sensitive data using cryptography and encryption. Today the use of
encryption is growing rapidly, being deployed in a much wider set of industry sectors
and across an increasing range of applications and platforms. Put simply,
cryptography and encryption have become one of the hottest technologies in the IT
security industry – the challenge now is to ensure that IT organizations are equipped
to handle this shift and are laying the groundwork today to satisfy their future needs.
35. Page | 32
Chapter 9
Conclusion
At the end of the day we need to protect our data. Increasingly, encryption
is being seen as the best way to ensure that data is protected, but the ever growing
use of encryption creates a management challenge. The challenge, however, doesn’t
need to be daunting. Implementing a flexible and extensible solution that automates
many of the time-consuming and error-prone key management tasks in an automated
enterprise-wide manner is rapidly becoming a priority for many organizations. In
order for enterprise-wide encryption to be deployed correctly, organizations need to
deploy the correct tool to manage the keys. In the same way that data protection has
moved from an IT challenge to a C-level issue, key management has become a high-
level business imperative.