Encrypting Files
Encrypting files is very much like encrypting strings. However, with large files, it may be wise to empty the cipher streams. However, if the file is too large, or if there are multiple files, then it may be wise to apply CipherStreams
—not to be confused with Stream Cipher.
CipherStreams
inherit most of their behavior from InputStream
and OutputStream
of Java, with the modification that you can decrypt a file you read, or encrypt a file you write with the supplied cipher.
Exercise 3: Encrypting a File
The following exercise displays how to encrypt a file. You can find this file in the code repository.
- Open the
Chapter10
project in IDEA if it's not already open. - Create a new Java class, using the
File
|New
|Java Class
menu. - Enter
Exercise3
as Name, and then selectOK
. You should now have an empty class in your project:package com.packt.java.chapter10; public class Exercise3 { }
- Add a
main
method in which you'll write the...