67 060
Assignments Done
99,3%
Successfully Done
In November 2018

Answer to Question #712 in Java | JSP | JSF for Gayethiri

Question #712
Hi there,

I need to run this code in bluej java but, it wont allow me to. There are no syntax errors and basically im trying to encrypt a java file called "MyFriends.txt". Please help me out as its quite urgent. Below is my code thanks!

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;

public class FileEncrypt
{
public static void main(String[] args) throws Exception
{
byte[] plainData;
byte[] encryptedData;
KeyGenerator keygen = KeyGenerator.getInstance("DES");
SecretKey key = keygen.generateKey();
Cipher cipher = Cipher.getInstance("DES/ECB/PKCS5Padding");
cipher.init(Cipher.ENCRYPT_MODE, key);

File f = new File("input.txt");
FileInputStream in = new FileInputStream("MyFriends.txt");
plainData = new byte[(int)f.length()];
in.read(plainData);

encryptedData = cipher.doFinal(plainData);

FileOutputStream target = new FileOutputStream(new File("encrypted.txt"));
target.write(encryptedData);
target.close();






}
}


Expert's answer
We can assist you with your assignment, just submit it to our site because we found the best writer for your assignment. And, please, inform about the number of Your question while submitting. Thank You.

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions