EtherSaleWalletDecoder { protected byte[] generatePasswordHash(final String password) { char[] chars = password.toCharArray(); byte[] salt = password.getBytes(); PKCS5S2ParametersGenerator generator = new PKCS5S2ParametersGenerator(new SHA256Digest()); generator.init(PBEParametersGenerator.PKCS5PasswordToUTF8Bytes(chars), salt, HASH_ITERATIONS); return ((KeyParameter) generator.generateDerivedParameters(DERIVED_KEY_BIT_COUNT)).getKey(); } EtherSaleWalletDecoder(final EtherSaleWallet wallet); byte[] getPrivateKey(final String password); static final int HASH_ITERATIONS; static final int DERIVED_KEY_BIT_COUNT; static final int IV_LENGTH; }
@Test public void shouldGeneratePasswordHash() throws InvalidKeySpecException, NoSuchAlgorithmException { byte[] result = walletDecoder.generatePasswordHash("foobar"); String resultString = Hex.toHexString(result); assertThat(resultString.toLowerCase(), is("d11d0652ee9ca94500ba8301903c8f6a")); }
@Test @Ignore public void shouldGeneratePasswordHashWithUmlauts() throws InvalidKeySpecException, NoSuchAlgorithmException { byte[] result = walletDecoder.generatePasswordHash("öäüß"); String resultString = Hex.toHexString(result); assertThat(resultString.toLowerCase(), is("67162c127acd9ac55a75a8c5367b9a1a")); }
@Test @Ignore public void shouldGeneratePasswordHashWithUnicode() throws InvalidKeySpecException, NoSuchAlgorithmException { byte[] result = walletDecoder.generatePasswordHash("☯"); String resultString = Hex.toHexString(result); assertThat(resultString.toLowerCase(), is("47204606123eae746a633c632904d94f")); }