@Test public void createHashTest() { JDBCHashStrategy strategy = new PBKDF2Strategy(vertx); String hashedPassword = strategy.computeHash("Paulo", "123456", -1); assertTrue(JDBCHashStrategy.isEqual("3EF08FDF601E24F9D9DF99F2A199A563E1EB4C8C467D61962B9526001EF6FA9F31C2F89FCA7690CF022E11AF89DA8BFD4D18E8A0FC888A745C8DD7AAB92A359B", hashedPassword)); }
@Override public String computeHash(String password, String salt, int version) { int iterations = DEFAULT_ITERATIONS; if (version >= 0) { if (nonces == null) { throw new VertxException("nonces are not available"); } if (version < nonces.size()) { iterations = nonces.getInteger(version); } } PBEKeySpec spec = new PBEKeySpec( password.toCharArray(), salt.getBytes(StandardCharsets.UTF_8), iterations, 64 * 8); try { byte[] hash = skf.generateSecret(spec).getEncoded(); if (version >= 0) { return bytesToHex(hash) + '$' + version; } else { return bytesToHex(hash); } } catch (InvalidKeySpecException ikse) { throw new VertxException(ikse); } }
PBKDF2Strategy extends AbstractHashingStrategy implements JDBCHashStrategy { @Override public String computeHash(String password, String salt, int version) { int iterations = DEFAULT_ITERATIONS; if (version >= 0) { if (nonces == null) { throw new VertxException("nonces are not available"); } if (version < nonces.size()) { iterations = nonces.getInteger(version); } } PBEKeySpec spec = new PBEKeySpec( password.toCharArray(), salt.getBytes(StandardCharsets.UTF_8), iterations, 64 * 8); try { byte[] hash = skf.generateSecret(spec).getEncoded(); if (version >= 0) { return bytesToHex(hash) + '$' + version; } else { return bytesToHex(hash); } } catch (InvalidKeySpecException ikse) { throw new VertxException(ikse); } } }
PBKDF2Strategy extends AbstractHashingStrategy implements JDBCHashStrategy { @Override public String computeHash(String password, String salt, int version) { int iterations = DEFAULT_ITERATIONS; if (version >= 0) { if (nonces == null) { throw new VertxException("nonces are not available"); } if (version < nonces.size()) { iterations = nonces.getInteger(version); } } PBEKeySpec spec = new PBEKeySpec( password.toCharArray(), salt.getBytes(StandardCharsets.UTF_8), iterations, 64 * 8); try { byte[] hash = skf.generateSecret(spec).getEncoded(); if (version >= 0) { return bytesToHex(hash) + '$' + version; } else { return bytesToHex(hash); } } catch (InvalidKeySpecException ikse) { throw new VertxException(ikse); } } PBKDF2Strategy(Vertx vertx); }
PBKDF2Strategy extends AbstractHashingStrategy implements JDBCHashStrategy { @Override public String computeHash(String password, String salt, int version) { int iterations = DEFAULT_ITERATIONS; if (version >= 0) { if (nonces == null) { throw new VertxException("nonces are not available"); } if (version < nonces.size()) { iterations = nonces.getInteger(version); } } PBEKeySpec spec = new PBEKeySpec( password.toCharArray(), salt.getBytes(StandardCharsets.UTF_8), iterations, 64 * 8); try { byte[] hash = skf.generateSecret(spec).getEncoded(); if (version >= 0) { return bytesToHex(hash) + '$' + version; } else { return bytesToHex(hash); } } catch (InvalidKeySpecException ikse) { throw new VertxException(ikse); } } PBKDF2Strategy(Vertx vertx); @Override String computeHash(String password, String salt, int version); }
PBKDF2Strategy extends AbstractHashingStrategy implements JDBCHashStrategy { @Override public String computeHash(String password, String salt, int version) { int iterations = DEFAULT_ITERATIONS; if (version >= 0) { if (nonces == null) { throw new VertxException("nonces are not available"); } if (version < nonces.size()) { iterations = nonces.getInteger(version); } } PBEKeySpec spec = new PBEKeySpec( password.toCharArray(), salt.getBytes(StandardCharsets.UTF_8), iterations, 64 * 8); try { byte[] hash = skf.generateSecret(spec).getEncoded(); if (version >= 0) { return bytesToHex(hash) + '$' + version; } else { return bytesToHex(hash); } } catch (InvalidKeySpecException ikse) { throw new VertxException(ikse); } } PBKDF2Strategy(Vertx vertx); @Override String computeHash(String password, String salt, int version);  }