How do I validate user’s password with PasswordEncryptor?

Every application that you’ll create may requires an authentication process. This authentication process will at least contains a process of checking user’s login name and their password. To make the system reliable the password we usually stored the password in an encrypted form.

The BasicPasswordEncryptor which implements the PasswordEncryptor interface provide a BasicPasswordEncryptor.encryptPassword(String password) method for encrypting user’s password. To check if the user’s password is correct we use the BasicPasswordEncryptor.checkPassword(String plainText, String encryptedPassword) method.

How do I create a message digest?

Creating a digest of a string message can be easily done using the general digester class Digester. First we need to get an instance of Digester, we call the class constructor and pass SHA-1 as the algorithm.

After having a Digester instance we create the message digest by executing or calling the Digester.digest(byte[] binary) method of this class.

How do I encrypt or decrypt bytes information using StandardPBEByteEncryptor?

This code demonstrate how to use the StandardPBEByteEncryptor class to encrypt and decrypt bytes information.

The result of our code are: