public static final String ALGORITHM = “PBKDF2WithHmacSHA512”; public static final int ITERATION_COUNT = 10000; public static final int KEY_LENGTH = 20; /* Bytes. 160 bit */ public static final int SALT_LENGTH = 4; /* Bytes. 32 bit */ public void store(String user, String password) { byte[] salt = new byte[this.SALT_LENGTH]; SecureRandom.getInstanceStrong().nextBytes(salt); SecretKeyFactory kf = SecretKeyFactory.getInstance(this.ALGORITHM); PBEKeySpec spec = new PBEKeySpec(password.toCharArray(), salt, this.ITERATION_COUNT, this.KEY_LENGTH); byte[] hash = kf.generateSecret(spec).getEnocoded(); this.store.put(user, new Entry(hash, salt)); }