From the course: Learn Java Cryptography

Unlock this course with a free trial

Join today to access over 25,500 courses taught by industry experts.

Performing symmetric encryption in Java

Performing symmetric encryption in Java - Java Tutorial

From the course: Learn Java Cryptography

Performing symmetric encryption in Java

- [Instructor] So now that we have a key we can do some actual encryption and decryption. So let's jump into the IDE. I'd like you to go ahead and open up in source main java our symmetric encryption utilities in com.frankmoley.crypto symmetric package. Now because we're going to use CBC, we need to do a few things to get started. So the first thing that we're going to do here is we're going to create a private static final string, and we're going to call this AES_CIPHER_ALGORITHM. Remember that we're using a block cipher, so it's not just AES, we also need to pass in the mode, which we're going to use CBC, and because we want to make sure that everything is padded correctly, we're going to use PKCS5Padding. Now essentially this is going to make sure that our block gets sufficient padding, we're going to use CBC, which means that we need an initialization vector. So let's go ahead and create a method in order to do that…

Contents