Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

*Experts please do not copy and paste from other sources because this is slightl

ID: 663809 • Letter: #

Question

*Experts please do not copy and paste from other sources because this is slightly different*

Part 1

File encryption is the science of writing the contents of a file in a secret code. Your encryption program should work like a filter, reading the contents of one file, modifying the data into a code, and then writing the coded contents out to a second file. The second file will be a version of the first file, but written in a secret code. Although there are complex encryption techniques, you should come up with a simple one of your own. For example, you could read the first file one character at a time, and add 10 to the character code of each character before it is written to the second file.

I would like you to modify the program slightly. You should ask the user what the number is that is going to be used for the Encryption. Therefore the program will prompt the user for a number and apply it to the data in the file to create the encrypted file.

Part 2

File Decryption Filter
Write a program that decrypts the file produced by the program in Part 1. The decryption program should read the contents of the coded file, restore the data to its original state, and write it to another file.

Explanation / Answer

// There are two types of encryption - public key and private key encryption algorithms

package net.codejava.crypting;

import java.io.File;

import java.io.FioleInputStream;

import java.io.FileOutputStream;

import java.io.IOException;

import java.security.InvalidKeyException;

import java.security.Key;

import java.security.NoSuchAlgorithmException;

import javax.crypting.WrongPaddingException;

import javax.crypting.Cipher;

import javax.crypting.IllegalBlockSizeException;

import javax.crypting.spec.SecretKeySpec;

public class CryptingUtils {

   private static final String ALGORITHM = "AES";

   private static final String TRANSFORMATION = "AES";

    public static void doEncrypt(String key, File ipFile, File opFile)

               throws CryptingException {

                          ExecuteCrypto(Cipher.ENCRYPT_MODE, key, ipFile, opFile);

      }

public static void main (String[] args) {

   BufferReader reader = new BufferReader(new InputStreamReader(System.in));

Sytem.out.println("Enter the number to be used for encryption);

    String number = reader.readLine();

     public static void doDecrypt(String key, File ipFile, File opFile)

                throws CryptingException {

                        ExecuteCrypto(Cipher.DECRYPT_MODE, key, ipFile, opFile);

         }

private static void ExecuteCrypto(int cipherMode, String key, File ipFile, File opFile) throws CryptingException {

    try {

      Key secretKey = new SecretKeySpec(key.getBytes(), ALGORITHM);

       Cipher cipher = Cipher.getInstance(TRANSFORMATION);

       cipher.init(cipherMode, secretKey);

       FileInputStream ipStream = new FileInputStream(ipFile);

     byte[] ipBytes = new byte[(int) ipFile.length()];

     ipStream.read(ipBytes);

    byte[] opBytes = cipher.ExecuteFinal(ipBytes);

    FileOutputStream opStream = new FileOutputStream(opFile);

    opStream.write(opBytes);

   ipStream.close();

opStream.close();

} catch (WrongPaddingException | NoSuchAlgorithmException | InvalidKeyException | BadPaddingException | IllegalBlockSizeException | IO Exception ex) {

      throw new CryptingException("Error while performing Encryption / Decryption of the file", ex);

}

}

}

package net.codejava.crypting;

public class CryptingException extends Exception {

    public CryptingException() {

}

public CryptingException(String message, Throwable throwable) {

       super(message, throwable);

}

}