PBKDF2WithHmacSHA1AccessTokenHasher implements AccessTokenHasher { @Override public byte[] hash(byte[] salt, byte[] accessToken) { try { SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1"); Base64.Encoder encoder = Base64.getEncoder(); char[] chars = encoder.encodeToString(accessToken).toCharArray(); KeySpec keySpec = new PBEKeySpec(chars, salt, 4096, 256); SecretKey secretKey = factory.generateSecret(keySpec); return secretKey.getEncoded(); } catch (Exception e) { throw new RuntimeException(e); } }  @Override byte[] hash(byte[] salt, byte[] accessToken);  }
@Test public void testHash() { PBKDF2WithHmacSHA1AccessTokenHasher hasher = new PBKDF2WithHmacSHA1AccessTokenHasher(); byte[] salt = new byte[20]; byte[] accessToken = new byte[20]; ThreadLocalRandom.current().nextBytes(salt); ThreadLocalRandom.current().nextBytes(accessToken); byte[] hash = hasher.hash(salt, accessToken); Assert.assertNotNull(hash); Assert.assertTrue(hash.length > 0); }