prng.nextBytes(salt); byte[] kdfPass = HashUtil.pbkdf2( password.getBytes(), salt,
.get("salt") .getAsString()); byte[] kdfPass = HashUtil.pbkdf2( password.getBytes(), salt,
@Test public void PBKDF2_SHA256_Random_Test() { String password = "testpassword"; int iterations = 262144; int len = 32; byte[] salt = new byte[32]; SecureRandom prng = new SecureRandom(); prng.nextBytes(salt); log.info("salt= {}", Hex.toHexString(salt)); byte[] pbkdf2Password = HashUtil.pbkdf2(password.getBytes(), salt, iterations, len, "SHA-256"); log.info(Hex.toHexString(pbkdf2Password)); assertNotNull(pbkdf2Password); }
@Test public void PBKDF2_SHA3512_Test() { String password = "testpassword"; byte[] salt = Hex.decode("ae3cd4e7013836a3df6bd7241b12db061dbe2c6785853cce422d148a624ce0bd"); int iterations = 262144; int len = 32; byte[] pbkdf2Password = HashUtil.pbkdf2(password.getBytes(), salt, iterations, len, "SHA3-512"); log.info(Hex.toHexString(pbkdf2Password)); assertArrayEquals(Hex.decode("2cf80c8e19136485eb79eba7349c8f334582f3b7f22e48e07124c4b5a85631c7"), pbkdf2Password); }
@Test public void PBKDF2_SHA512_Test() { String password = "testpassword"; byte[] salt = Hex.decode("ae3cd4e7013836a3df6bd7241b12db061dbe2c6785853cce422d148a624ce0bd"); int iterations = 262144; int len = 32; byte[] pbkdf2Password = HashUtil.pbkdf2(password.getBytes(), salt, iterations, len, "SHA-512"); log.info(Hex.toHexString(pbkdf2Password)); assertArrayEquals(Hex.decode("5e005b008b20c7ab157725ed2f72faa4357a51eddac85837ca7d925e8daa0d41"), pbkdf2Password); }
@Test public void PBKDF2_KECCAK256_Test() { String password = "testpassword"; byte[] salt = Hex.decode("ae3cd4e7013836a3df6bd7241b12db061dbe2c6785853cce422d148a624ce0bd"); int iterations = 262144; int len = 32; byte[] pbkdf2Password = HashUtil.pbkdf2(password.getBytes(), salt, iterations, len, "KECCAK-256"); log.info(Hex.toHexString(pbkdf2Password)); assertArrayEquals(Hex.decode("c5a5e1ea4b87eff0119d4cedf89401c4777d0f1b374c654bb65026eb570183b7"), pbkdf2Password); }
@Test public void PBKDF2_SHA256_Test() { String password = "testpassword"; byte[] salt = Hex.decode("ae3cd4e7013836a3df6bd7241b12db061dbe2c6785853cce422d148a624ce0bd"); int iterations = 262144; int len = 32; byte[] pbkdf2Password = HashUtil.pbkdf2(password.getBytes(), salt, iterations, len, "SHA-256"); log.info(Hex.toHexString(pbkdf2Password)); assertArrayEquals(Hex.decode("f06d69cdc7da0faffb1008270bca38f5e31891a3a773950e6d0fea48a7188551"), pbkdf2Password); }
@Test public void PBKDF2_SHA1_Test() { String password = "testpassword"; byte[] salt = Hex.decode("ae3cd4e7013836a3df6bd7241b12db061dbe2c6785853cce422d148a624ce0bd"); int iterations = 262144; int len = 32; byte[] pbkdf2Password = HashUtil.pbkdf2(password.getBytes(), salt, iterations, len, "SHA-1"); log.info(Hex.toHexString(pbkdf2Password)); assertArrayEquals(Hex.decode("279af536192ea4f5dac04f96471d94ea174c38d4b9a9a908f03217a215fc01f8"), pbkdf2Password); }
@Test public void PBKDF2_SHA3256_Test() { String password = "testpassword"; byte[] salt = Hex.decode("ae3cd4e7013836a3df6bd7241b12db061dbe2c6785853cce422d148a624ce0bd"); int iterations = 262144; int len = 32; byte[] pbkdf2Password = HashUtil.pbkdf2(password.getBytes(), salt, iterations, len, "SHA3-256"); log.info(Hex.toHexString(pbkdf2Password)); assertArrayEquals(Hex.decode("2761ad467ba3d88c8c331e93829ec5ce912048037c50c8d5faeb4af87bbeb102"), pbkdf2Password); }
log.debug("salt: {}", Hex.toHexString(salt)); byte[] kdfPass = HashUtil.pbkdf2( password.getBytes(), salt,
@Test public void testEncryptDecrypt_WithIv() throws InvalidCipherTextException { byte[] plainBytes = "01234567890123450123456789012345345".getBytes(); log.info("plain: {}", Hex.toHexString(plainBytes)); String password = "Aa1234567890#"; log.info("password: {}", password); byte[] iv = new byte[16]; byte[] salt = new byte[32]; SecureRandom prng = new SecureRandom(); prng.nextBytes(iv); prng.nextBytes(salt); byte[] kdfPass = HashUtil.pbkdf2( password.getBytes(), salt, WALLET_PBKDF2_ITERATION, WALLET_PBKDF2_DKLEN, WALLET_PBKDF2_ALGORITHM); byte[] encData = AESEncrypt.encrypt( plainBytes, ByteUtil.parseBytes(kdfPass, 0, 16), iv); log.info("encrypt: {}", Hex.toHexString(encData)); byte[] plainData = AESEncrypt.decrypt( encData, ByteUtil.parseBytes(kdfPass, 0, 16), iv); log.info("decrypt: {}", Hex.toHexString(plainData)); assertArrayEquals(plainBytes, plainData); }
prng.nextBytes(salt); byte[] kdfPass = HashUtil.pbkdf2( password.getBytes(), salt,
log.debug("salt: {}", Hex.toHexString(salt)); byte[] kdfPass = HashUtil.pbkdf2( password.getBytes(), salt,