





















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
A project report on Image Encryption and Decryption Using AES
Typology: Assignments
Limited-time offer
Uploaded on 06/07/2020
3.8
(5)6 documents
1 / 29
This page cannot be seen from the preview
Don't miss anything!
On special offer
Information and System Security A PROJECT REPORT Submitted by P. Jahnavi - 17MIS G. Baby Sai Meghana Chowdary – 17MIS
Under the Guidance of Dr. S. Sudhakar Ilango Associate Professor, CSE, VIT-AP
Chapter - Background Study AES, Advanced Encryption Standard is a symmetric-key algorithm based on the Rijndael cipher developed by Joan Daemen and Vincent Rijmen. The AES algorithm has a block size of 128 bits. It supports three different key lengths of 128, 192 and 256 bits. AES replaced Data Encryption Standard and it is now used worldwide. The cipher consists of rounds, where the number of rounds depends on the key length: 10 rounds for a 128 bit key, 12 rounds for 192 bit key, and 14 rounds for a 256 bit key. The whole algorithm operates on a 4 x 4 matrix of bytes. The first rounds consist of four distinct transformation functions: Sub Bytes, Shift Rows, Mix Columns, and Add Round Key. The final round contains three transformations. The Mix Columns function is not used in the final round. Each transformation takes one or more 4x4 matrices as input and produces a 4x4 matrix as output. Provided that all the four rounds are reversible, it is easy to prove that decryption does recover the plaintext
Chapter - Problem Definition
Many encryption methods have been proposed in literature, and the most common way to protect large multimedia files is by using conventional encryption techniques, Private key bulk encryption algorithms, such as Triple DES, are not so suitable for transmission of images. Due to complexity of their internal structure, they are not particularly fast in terms of execution speed and cannot be applied for images in the real time scenario Also traditional cryptographic techniques such as DES cannot be applied to images due to intrinsic properties of images such as bulk data capacity, redundancy and high correlation among pixels. Image encryption algorithms can become an integral part of the image delivery process if they aim towards efficiency and at same time preserve the security level.
Chapter - Methodology/Procedure
Chapter - Results and Discussion The experiments are performed on a Lenovo Laptop with Intel Core i3-4030U CPU running at 1.90GHz, and supported by 8GB of RAM. The algorithm proposed in this paper is implemented using NetBeansIDE-8.2. Crypto module is used for the AES algorithm. The implementation also provides an optional user friendly interface to perform encryption and decryption operations. By selecting images of various sizes, qualities and formats, an honest evaluation of the algorithm in terms of its efficiency, performance is made possible. We can also give different keys for same age and check whether it is same. Once a key is given to encrypt an image then the decryption must be with same key or else it doesn’t give the result. It is clear that the proposed algorithm can handle images of various categories, file sizes, qualities and resolutions. The size of the output is based on the key size specified in the encryption phase
References
Appendix – A Coding import java.awt.; import java.awt.image.; import java.awt.event.; import javax.swing.; import javax.imageio.ImageIO; import java.io.File; import java.util.Random; import javax.crypto.; import javax.crypto.spec.; import static javax.swing.JFrame.EXIT_ON_CLOSE; class Main extends JFrame implements ActionListener{ private ImageRead panel; private ImageEncrypt encrypter; private File fileName; public Main(){ setDefaultCloseOperation(EXIT_ON_CLOSE); setTitle("JAVA-ImageCrypto"); setLayout(new BorderLayout()); panel = new ImageRead(); getContentPane().add(panel);
file.addSeparator();file.add(close); menu.add(setkey); menu.addSeparator(); menu.add(Encrypt); menu.add(Decrypt); help.add(about); menuBar.add(file); menuBar.add(menu); menuBar.add(help); open.addActionListener(this); setkey.addActionListener(this); close.addActionListener(this); save.addActionListener(this); Encrypt.addActionListener(this); about.addActionListener(this); saveas.addActionListener(this); Decrypt.addActionListener(this); return menuBar; } public void setFile(File file){ fileName = file; } public void actionPerformed(ActionEvent action) { String text = action.getActionCommand(); try{ if(text == "Open .."){ actionLoadImage(null); } else if(text == "Save"){ actionSaveImage(fileName); } else if(text == "Save as .."){ actionSaveImage(null);} else if(text == "Close "){ System.exit(0);} else if(text == "Set Pass Key"){ actionKeyDialog();
else if(text == "Encrypt Image"){ panel.setImage(encrypter.map(panel.getImage(),true,false)); } else if(text == "Decrypt Image"){ panel.setImage(encrypter.map(panel.getImage(),false,false)); } else if(text == "About"){ DisplayContactinfo(); } }catch(Exception err) { System.out.println("ERROR:" + err);} } public void actionKeyDialog(){ String key = new String(encrypter.getKey()); key = (String)JOptionPane.showInputDialog(this, "Enter a 16 byte key (current key= " + key.getBytes().length + " bytes)",key); while(key != null && key.getBytes().length != 16){ key = (String)JOptionPane.showInputDialog(this, "Enter a 16 byte key (current key= " + key.getBytes().length + " bytes)",key); }
public void actionSaveImage(File imageFile){ if(imageFile == null){ JFileChooser filechooser = new JFileChooser(fileName); filechooser.showSaveDialog(this); imageFile = filechooser.getSelectedFile(); }
if(imageFile != null){ try{ ImageIO.write(panel.getImage(), "png", imageFile); }catch(Exception e){ System.out.println("Error:" + e); } setFile(imageFile); } } public void DisplayContactinfo(){ JFrame contact = new JFrame("Contact info"); contact.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); contact.setSize(new Dimension(500, 430)); contact.setLayout(new BorderLayout()); contact.setDefaultCloseOperation(3); contact.setResizable(false);
JTextArea cont1 = new JTextArea(About); contact.add(new JScrollPane(cont1), BorderLayout.CENTER); cont1.setEditable(false); contact.setVisible(true); } public static void main(String args[]) { Main win = new Main(); win.setVisible(true); if(args.length > 0){ win.actionLoadImage(new File(args[0])); } } } class ImageRead extends JPanel{ private BufferedImage image; public ImageRead() { this.image = null; setFocusable(true); setLayout(null); setOpaque(true); }
private Cipher cipher; private SecretKeySpec skeySpec; ImageEncrypt() { try{ generator = new Random(); KeyGenerator kgen = KeyGenerator.getInstance("AES"); kgen.init(128); SecretKey skey = kgen.generateKey(); byte[] raw = skey.getEncoded(); skeySpec = new SecretKeySpec(raw, "AES");
cipher = Cipher.getInstance("AES/ECB/NoPadding"); }catch(Exception e){ System.out.println("ERROR: " + e);} } public void setKey(byte [] key){ skeySpec = new SecretKeySpec(key,"AES"); } byte [] getKey(){ return skeySpec.getEncoded();} public BufferedImage map(BufferedImage image,boolean encrypt,boolean trick) throws Exception{ if(image.getWidth() % 2 != 0 || image.getHeight() % 2 != 0){ throw(new Exception("Image size not multiple of 2 :(")); } BufferedImage encImage = new
BufferedImage(image.getWidth(),image.getHeight(), BufferedImage.TYPE_4BYTE_ABGR); if(encrypt){ System.out.println("Encrypting Image ... trick=" + trick); cipher.init(Cipher.ENCRYPT_MODE, skeySpec); } else{ System.out.println("Decrypting Image ... trick=" + trick); cipher.init(Cipher.DECRYPT_MODE, skeySpec); }
for(int x=0;x<image.getWidth(); x+=2){ for(int y=0;y<image.getHeight(); y+=2){ if(verbose) System.out.println("Block: (" + x+","+y+") -----"); int counter =0; byte [] pixelBytes = new byte[16]; for (int i=0;i<2;i++){ for (int j=0;j<2;j++){ int val = image.getRGB(x+i,y+j); if(trick && encrypt) val +=x*y; byte [] sub = intToByteArray(val); if(verbose){ System.out.println("Val: " + val + " Bytes: ");