article: How to store passwords securely with PBKDF2 | by Kasun Dharmadasa | Medium

import org.apache.commons.codec.binary.Hex;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.PBEKeySpec;
import java.io.UnsupportedEncodingException;
import java.security.NoSuchAlgorithmException;
import java.security.spec.InvalidKeySpecException;

/**
 * This is the Main class.
 */
public class MyClass {
    
    public static String oldHash = "4d7b9ce57b1ba8eb25012213d9b0de3dbb8ca3a25db9ee2b5d1c15f036d1a495c81edfcce6eb8df02ebf3206d925c62eee2f4bf21ba31785b99d2bc3f27ee43ca872f43f895290b1d9dd32fcc75ce9666a894d862f98900e6e10fe559ffd77c0a6114f570dee9258c6f62eeacc22b86834bebf6c3fc3339aa14c67801571d06c92f9ffa423fe8d1cd43ce15e7964be6bc88bd715cca2327cbd6404333bc975e72008aeed5de5b9b04553930dd597e7501089abe64ad7b3fa8aef614e152c3632fc7857a22c5ccee74629196e96d52015ff6fb39d3d9e2f0caeb08bd5e1d7e25e4a0ebdb02ea543c21792f988dcd14402669fe5557258aad4d6314e46bebfbbe52991344bdd062068470428f76685cc97ba383ef9f2eb28912c8deacf8f39cb7aedb2a500b396831b7c1d34f1c2ca4a2ff277a18dae48025cb44822a2dea1893297522f1a131a6e53e6535ad4cfe902954a10f99d8f333431d781457892a992981e3237940bca0cdf235d74cb30ef8c24766d407da419826d1c1dbe6556d04df7f4f41742224b00e4660c9a2b3b0e642b1785a891377feedd5760cac5d565a1f74b65a19bde61154e4df5be9e3ab1930017dbd43fc37b3435aa4155b0ca241c08eb474d54f502e762f4a8233376891de880bdb6cc5f597bed4a189f2770efb900c5bc5459d2a98827402975861220dbe886c452021e101f234975c1810c2904df";

    
    public static void main(String[] args) throws UnsupportedEncodingException {

        String password = "abc123123123";
        String salt = "765537a40501e85db7e41ec975db67b0cd21ab4647924e8be1aa00630d1c5162";
        int iterations = 25000;
        int keyLength = 512;
        char[] passwordChars = password.toCharArray();
        byte[] saltBytes = salt.getBytes();

        byte[] hashedBytes = hashPassword(passwordChars, saltBytes, iterations, keyLength);
        String hashedString = Hex.encodeHexString(hashedBytes);

        System.out.println(hashedString);
        
        System.out.println(oldHash.contains(hashedString));
    }

    public static byte[] hashPassword( final char[] password, final byte[] salt, final int iterations, final int keyLength ) {

        try {
            SecretKeyFactory skf = SecretKeyFactory.getInstance( "PBKDF2WithHmacSHA256" );
            PBEKeySpec spec = new PBEKeySpec( password, salt, iterations, keyLength );
            SecretKey key = skf.generateSecret( spec );
            byte[] res = key.getEncoded( );
            return res;
        } catch ( NoSuchAlgorithmException | InvalidKeySpecException e ) {
            throw new RuntimeException( e );
        }
    }
}