Chapter 4
74
There is a BASE64 encoder and decoder in the sun.misc package. Since this is not included in a java.*
package, its location could change in a future release of Java.
For that reason, we have provided a BASE64 encoder and decoder in Appendix C of this book.
We can use it as a drop-in replacement for the sun.misc implementation, by changing the import
statement in PBE.java from:
import sun.misc.*;
to
import com.isnetworks.base64.*;
and include the BASE64 classes in the classpath.
Our code example will have two options: encryption and decryption. Encryption will require a password
and some plaintext, and decryption a password and some encrypted data. We'll create a salt for the
encryption and prepend it to the ciphertext after it's been encrypted, like so:
PBE Cipher
Ciphertext
Plaintext
Message
Password
New salt
Salt
Ciphertext
Encrypted Data
BASE64 Encode
BASE64 Encode
When decrypting, we'll take that block of encrypted data and separate it into the salt and the ciphertext.
Then we can use the password and the salt to initialize a cipher that can decrypt the ciphertext into the
original plaintext message like this:
PBE Cipher
Ciphertext
Ciphertext
Password
Salt
Salt
Ciphertext
Encrypted Data
BASE64 Decode
BASE64 Decode