Encryption is the process of converting plain text data (plaintext) into something that appears to be random and meaningless (ciphertext). Decryption is the process of converting ciphertext back to plaintext.
The goal of every encryption algorithm is to make it as difficult as possible to decrypt the generated ciphertext without using the key. If a really good encryption algorithm is used, there is no technique significantly better than methodically trying every possible key. For such an algorithm, the longer the key, the more difficult it is to decrypt a piece of ciphertext without possessing the key.
It is difficult to determine the quality of an encryption algorithm. Algorithms that look promising sometimes turn out to be very easy to break, given the proper attack. When selecting an encryption algorithm, it is a good idea to choose one that has been in use for several years and has successfully resisted all attacks.
You can also design your own Encryption and Decryption algorithm, like you just reverse the input string while encrypting it and same process you apply the encrypted data to get the original one.
suppose password field for user you store in database in encrypted format just to make it secure by other database users just apply the encryption algorithm on user input, suppose user entered the password as ´!@#$%´ while registering on the application, but you store in DB as ´%$#@!´. Now at login time you apply the same while validating the credentials.
Generally in java we use BASE64 Encoding and Decoding. Java 8 now supports BASE64 Encoding and Decoding.You can use the following classes: java.util.Base64, java.util.Base64.Encoder and java.util.Base64.Decoder..
// encode with padding
String encoded = Base64.getEncoder().encodeToString(someByteArray);
// encode without padding
String encoded = Base64.getEncoder().withoutPadding().encodeToString(someByteArray);
// decode a String
byte  barr = Base64.getDecoder().decode(encoded);