Hello,
please help me with the follpowing question in java, thank you in advance
please find the java program written below :
--------------------------------------------------------------------------------------------------------
import java.util.*;
import java.io.*;
import java.security.*;
//importing security packages
import javax.crypto.*;
import javax.crypto.spec.SecretKeySpec;
public class test {
static final String ALGORITHM =
"AES";
//defining that we will use AES algorithm
static final String TRANSFORMATION = "AES";
public static void main (String[] args)
{
InputReader in = new
InputReader(System.in); //creating
input reader
PrintWriter w = new
PrintWriter(System.out); //creating
writer
System.out.println("please enter your name :
"); //taking username as
input
String name =
in.nextLine();
System.out.println("Please enter the input file name : ");
File inputFile = new
File(in.nextLine());
System.out.println("Enter the password for secret
key"); //taking password input
for key
//using make key method
for using password as key with some manupulation
String key =
makeKey(in.nextLine());
File encryptedFile =
new File("encrypted.txt");
File decryptedFile = new
File("decrypted.txt");
encryptWithAES(key,
inputFile, encryptedFile);
decryptWithAES(key, encryptedFile, decryptedFile);
w.close();
}
//defining encrypt method
public static void encryptWithAES(String key,
File inputFile, File outputFile) {
doCrypto(Cipher.ENCRYPT_MODE, key, inputFile, outputFile);
}
//defining decrypt method
public static void decryptWithAES(String key,
File inputFile, File outputFile) {
doCrypto(Cipher.DECRYPT_MODE, key, inputFile, outputFile);
}
//making key from given password
public static String makeKey(String pass)
{
while (pass.length()
< 16) {
pass += pass;
}
return pass.substring(0,
16);
}
//function for encryption and decryption
public static void doCrypto(int cipherMode,
String key, File inputFile, File outputFile) {
try {
//taking secret key and algorithm to be used
Key secretKey = new SecretKeySpec(key.getBytes(), ALGORITHM);
Cipher cipher = Cipher.getInstance(TRANSFORMATION);
cipher.init(cipherMode, secretKey);
//getting input file stream
FileInputStream inputStream = new FileInputStream(inputFile);
byte[] inputBytes = new byte[(int) inputFile.length()];
inputStream.read(inputBytes);
//creating output byte stream
byte[] outputBytes = cipher.doFinal(inputBytes);
//creating output file from output byte stream
FileOutputStream outputStream = new
FileOutputStream(outputFile);
outputStream.write(outputBytes);
inputStream.close();
outputStream.close();
}
//throwing exception if
error occurs
catch
(NoSuchPaddingException | NoSuchAlgorithmException
| InvalidKeyException | BadPaddingException
| IllegalBlockSizeException | IOException ex) {
System.out.println("Error encrypting/decrypting file: " +
ex);
}
}
}
-------------------------------------------------------------------------------------------------------------------
please find the screenshots of code, its execution along with different input and output files :
Hello, please help me with the follpowing question in java, thank you in advance
Hello, please help me with the following question, below is the code for the tutorial provided for us is the following tutorial and the code in java http://tutorials.jenkov.com/java-cryptography/index.html https://docs.google.com/document/d/1_xZ09sbNjy9BCjgQhZrrRop4UrtXmUk2yKwSghIe1Cs/edit?fbclid=IwAR3ATn39Jm9odLYtvvndhDR6NQTZGb9yiiSpAamDwTwj5Hyk0B-cVraMqOw , thank you for your help in advance, Create a Java program based on the Java Cryptography API to do the following: Accept a user password from the user Accept a file name from the user Encrypt/Decrypt the file using symmetric key techniques with CBC The key should be based on...
Hello, Could you please help me to answer this question in details Thank you 1. The nurse is collaborating with the health care team to create a plan of care for a client following a stroke. Explain the nurse's role in continuity of care.
Hello, Could you please help me to answer this question in detail? Thank you XX A.2.A. E E . Normal 1 No Spac... Heading! Heading 2 Title Seite ang 2. What is the expected growth mile markers for a 6 month infant?
Hello, Please help me answer this question. Thank you:) 20.00 mL of HCl(aq) is titrated to its end point with 21.4 mL of 0.25 M Mg(OH)2(aq). What is the concentration and the pH of the acid?
Hello, Can you please help me to answer this question in details? Thank you 3. An 8-hour post-partum client complains of abdominal cramping and feeling dizzy.During the assessment the nurse notes the client?s fundus is soft, deviated to the right and 4 fingerbreadths above the umbilicus, and there is moderate rubra What would the nurse?s priority actions be?
Hello expert, Please help me to answer this question. Thank you! U.S. healthcare spending directly contributes to lower infant mortality and higher life expectancy rates globally. a. True b. False
please help me with this question thank you very much in advance Using a structure and an appropriate fixed integer datatype, declare a bit-field consisting of the following fields: bmonth: 4 bits bday: 5 bits bweekday: 3 bits cgrade: 4 bits Use tag_data as the tag name of this structure. TTT Arial 1412pt T Path: P Words:0
hello, can you please help me with the problem below, thank you in advance. Panamint Systems Corporation is estimating activity costs associated with producing disk drives, tapes drives, and wire drives. The indirect labor can be traced to four separate activity pools. The budgeted activity cost and activity base data by product are provided below. Activity Cost Activity Base Procurement $337,800 Number of purchase orders Scheduling $209,800 Number of production orders Materials handling $489,500 Number of moves Product development $703,500...
Hello! :) Could someone please assist me? Thank you in advance. I appreciate you. Q: What is the major product formed in each reaction? 13. What is the major product formed in each of the following reactions. CH,CH2CHCH3 + H2O DON BHs H2O2 (CH3)2 CH CH CH HO CH,CH=CH2 + HBr - CECH HgSO4 H20/H2SO4 x H2SO4 H2SO4 ethanol B & NOCH + NaOCH3 OH Na2Cr2O7 H2SO4 CH3NH2 + HBr HE OCH.CH
Hello, can you please help me with providing the product for the below reaction? thank you + HC=C Na (1)NH,(1), - 33C (2)H,0* Co H, COCH, + HC=CMgBr (1) Et, (2)H,0*