[solved] – 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 Answer
OR

