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!
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();
}
}
1
Expert's answer
2010-10-05T19:19:49-0400
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.
Comments
Leave a comment