Transmitting confidential data such as plain text password through wire is always vulnerable to security.It is always recommended to encrypt such information and use SSL to transmit those confidential data.Java provides multiple encryption algorithm for this.In this post, we will be discussing about AES(Advanced Encryption Standard) symmetric encryption algorithm in java which with CBC mode is faster and more secure than 3DES.
As we know, there are 2 basic types of encryption - Asymmetric and Symmetric encryption. Asymmetric encryption uses two different keys as public and private keys.Here, you can encrypt sensitive information with a public key and a matching private key is used to decrypt the same.Asymmetric encryption is mostly used when there are 2 different endpoints are involved such as VPN client and server, SSH etc.
Similarly, we have another encryption technique called as Symmetric encryption.This type of encryption uses a single key known as private key or secret key to encrypt and decrypt sensitive information.This type of encryption is very fast as compared to asymmetric encryption and are used in systems such as database system.Some examples of symmetric encryptions are Twofish, Blowfish, 3 DES, AES.
AES stands for Advanced Encryption System and its a symmetric encryption algorithm.It is a specification for the encryption of electronic data established by the U.S. National Institute of Standards and Technology (NIST) in 2001.Here is the wiki link for AES.The AES engine requires a plain-text and a secret key for encryption and same secret key is required to again decrypt it.
The input can be of 128 bit or 192 bit or 256 bit and corresponding bit of cipher text is generated.
Following is the sample program in java that performs AES encryption.Here, we are using AES with CBC mode to encrypt a message as ECB mode is not semantically secure.The IV mode should also be randomized for CBC mode.
If the same key is used to encrypt all the plain text and if an attacker finds this key then all the cipher can be decrypted in the similar way.We can use salt and iterations to improve the encryption process further.In the following example we are using 128 bit encryption key.Here is an online tool for aes encryption.
Following is the reverse process to decrypt the cipher.The code is self explainatory.
Following is the main() implementation to test our AES implementation.
Following is the result.
Contact us: email@example.com